File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Shaik Muhammad
Ranch Hand
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 225
Debian Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9214
9
Linux Mac OS X Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't fit 32 bits in a byte. Look at Carey's example
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic