Regarding byte transfer from java socket to c
2 posts in topic
Flat View  Flat View

Posted By:   Akilan_Arunagiri
Posted On:   Saturday, May 19, 2001 10:34 AM

How do I split a decimal value into an Hexadecimal value and store it as two bytes in java...say for example

if 09 is the decimal
I can give it as

byte b1 = 0x00
byte b2 = 0x09

how do I give 82 as same as above
Could u please explain this with other examples also..?
expecting ur reply

Re: Regarding byte transfer from java socket to c

Posted By:   Christopher_Schultz  
Posted On:   Monday, May 21, 2001 12:02 PM

If you use a DataOutputStream, you can just dump data to it, and ti will be automatically converted to network byte-order for you.

Therefore, you can do:

DataOutputStream dos = new DataOutputStream();


If you really want to do binary-coded decimal (which is what you are doing above), then you'll have to convert each number to a character representing your digit (i.e. convert 1 to "1") and then send those bytes as text.

I think that's more trouble that it's worth.


Re: Regarding byte transfer from java socket to c

Posted By:   Michael_Wax  
Posted On:   Sunday, May 20, 2001 06:41 PM

Are you saying that you want to work digit-by-digit, or do a straight decimal-to-hexadecimal conversion, in which case each byte will not be directly assignable to a digit in the decimal value? If the latter, you can do it without writing very little code by using the static method Integer.toHexString(int value) to give you a String representation of the hexadecimal value, following by application of the appropriate method in the Byte class to convert each character to a byte.
About | Sitemap | Contact