Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Convert an int value to a one byte hex

807589Jul 21 2008 — edited Jul 21 2008
How can I convert an int value to a one byte hex.

I have tried the following but it is returning a two byte value.
Integer.toHexString(intValue);
I am trying to send a one byte hex value inside a message. What I do is construct the message, calculate an inValue and then try to convert it as a hex and add it into it. This message is finally sent as a stream of bytes.

For example:

The message structure is like this:
Message: "\u0003"|Integer.toHexString(intValue)|BODY|"\u0004"
I need to add this inValue as a hex. Moreover, I need it to be sent as a one byte hex value.


When I use the above method to get the hex value I end up with a stream of bytes that looks like this:

3
36 <-- The first part of the hex value.
36 <-- The second part of the hex value.
xx
xx
...
4

What I need instead is this:

3
36 <-- Only one hex value as one byte.
xx
xx
...
4

How can I achieve that?

Thanks,

B.D.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 18 2008
Added on Jul 21 2008
12 comments
1,130 views