Re: String to byte[] -- I cant get there from here?
RVince wrote:
I have to read the input from a socket connection. The
first byte represents the length of the message in hex, so it can be
something like, 6B. I can read the byte and convert it to the length.
The characters "0F" ("zero eff") or "6B" ("six bee") will not fit in a single
byte, so what you wrote here doesn't make sense. What does fit in a byte is
the numeric value 0x0F, which is EXACTLY THE SAME as 15.
However, when I send the response, I need to comport to this standard
and send my length (which I have as an int and as a two-character long
String representing what the byte in hex should look like) but I need
to send it as a byte in hex. So, for example, if the length is merely
15 bytes, I need to send a 0F as a byte. I THINK, based on what you;ve
said here, that this would be the equivalent of (byte)15.
A byte, as several people keep telling you, just holds a numeric quantity. 0F
hex is THE SAME NUMBER as 15 decimal.
So if you have the following code snippet:
byte zeroEff = (byte) 0x0F;
byte fifteen = (byte) 15;
boolean theSame = (zeroEff == fifteen);
the value of 'theSame' after the assignment will be 'true'.
Ergo, one way to send a byte value 0x0F to an output stream 'out' would be
out.write( 15 );
--
Lew