| Author |
long Value to byte Array of size 4
|
Karthik Rajendiran
Ranch Hand
Joined: Aug 13, 2004
Posts: 209
|
|
Hello Friends, I have long value ,which i need to store in byte array of size 4.How to do that Can any one please give me the code?
|
SCJP 1.4 SCWCD 1.4 SCDJWS 1.4
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16809
|
|
A "long" value is 64 bits -- which means that it needs a byte array of size 8. Unless of course, you mean an "int" value. Anyway, here is the easiest way to do this... BTW, if this is a homework question, it would be highly unlikely that your teacher will accept this solution. He/She is probably looking for a combination of shift/and/or operators. Henry [ October 27, 2006: Message edited by: Henry Wong ]
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Karthik Rajendiran
Ranch Hand
Joined: Aug 13, 2004
Posts: 209
|
|
Hello Henry Thanks for your input. BTW it is not homework question. We need to store one CRC value long in a byte array of size 4 Is it possible to do some base64 coding or compression technique?
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16809
|
|
Is it possible to do some base64 coding or compression technique?
Base64 will actually expand the size -- every 5 bits will become 8 bits. As for compression, unlikely. A CRC is a checksum. No common patterns. No large groups of ones or zeros. It is unlikely to get any compression on a CRC, much less get it down to half it's size. BTW, I always thought CRC was much smaller than 64 bits. When I used them, more than a decade ago, they were only 16 bits. I guess they added much stronger checksums. Henry [ October 28, 2006: Message edited by: Henry Wong ]
|
 |
 |
|
|
subject: long Value to byte Array of size 4
|
|
|