• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

long Value to byte Array of size 4  RSS feed

 
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
author
Posts: 23832
140
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Karthik Rajendiran
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23832
140
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ]
 
I miss the old days when I would think up a sinister scheme for world domination and you would show a little emotional support. So just look at this tiny ad:
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!