This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes How to convert binary octet string into byte array for writing into socket Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "How to convert binary octet string into byte array for writing into socket" Watch "How to convert binary octet string into byte array for writing into socket" New topic
Author

How to convert binary octet string into byte array for writing into socket

Shaik Muhammad
Ranch Hand

Joined: Jul 16, 2008
Posts: 36
I need to convert binary octet string into byte array for writing into socket.
ie i have to convert the octet string "00000010" into byte array with the value 00000010. How to do this?
Carey Evans
Ranch Hand

Joined: May 27, 2008
Posts: 225

Byte.parseByte("00000010",2) returns the binary value (that is, 2) as a byte. You will need to do this to every eight binary digits in your input and write them into each element of a byte array.
Shaik Muhammad
Ranch Hand

Joined: Jul 16, 2008
Posts: 36
Thanks.. I want to write the integer 160 as binary string into a byte array.
Am getting numberformat exception as the input argument is out of range of -128 to 127. pl help
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8702
    
    6

You can't fit 32 bits in a byte. Look at Carey's example


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to convert binary octet string into byte array for writing into socket
 
Similar Threads
snmp agent not responding
Integer converts to 2 octet integer?
byte array to string
Read integers from a char array buffer
Convert byte[] to String