Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 280
  • Last Modified:

Difference between storing bytes in C and Java

What are the differences in C and Java when it comes to storing bytes?
Is there anything to do with Big/Little Endian?
I have some conversion from C to Java to do, and would need some advice
on this so that I can take note of the areas which are different.
Thanks.
0
jasminekwok
Asked:
jasminekwok
1 Solution
 
bhayzoneCommented:
I dont think C has any byte datatype like java does.

I also think the endian-ness is a characteristic of the hardware architechture rather than software. For example Intel mite use big-endian while AMD mite be using little-endian.

I guess the only thing that would differ would be the character set ... not too sure on this one.
0
 
yongsingCommented:
For just C alone, the bytes stored could be in big endian or in little endian, depending on the hardware. On Intel machines, they are in big endian.

For Java, I think it's just in big endian.
0
 
bhayzoneCommented:
I dont think C has any byte datatype like java does.

I also think the endian-ness is a characteristic of the hardware architechture rather than software. For example Intel mite use big-endian while AMD mite be using little-endian.

I guess the only thing that would differ would be the character set ... not too sure on this one.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
jasminekwokAuthor Commented:
Ok, seems like big/little endian is not an issue to me now. But what about the differences in the languagge itself. Like in C, unsigned char is 1 byte, and char is 2 bytes in Java. Is there such a difference for bytes?
0
 
yongsingCommented:
The definition of a byte is 8 bits. In C, a "char" dat type is used to hold a byte value, whereas in Java, a "byte" data type is used to hold a byte value.
0
 
sciuriwareCommented:
Obviously you are dealing with data transfers between C and JAVA via networks or files.
1) as yongsing said: bytes are bytes, no problem there.
2) when it comes to JAVA char: convert them to bytes or to (Microsoft C) wide characters; I prefer the first.
3) 16-bits, 32-bits and 64-bits values give rise to huge problems (even not talking about float and double).
For instance: when I had to exchange binary data between UNISYS, HP, DEC-ALPHA and SUN (solely in ANSI C) the only reliable format appeared to be time_t integers.
With this in mind: please convert all your data to ASCII and don't mind the overhead when converting to and from.
That approach also overcomes the problems with different floating formats.
Two snakes in the grass might be that official C doesn't support 64-bits integers, and that JAVA won't support unsigned integers, but that won't block you; does it?
;JOOP!
0
 
CEHJCommented:
Also bytes are signed in Java
0
 
CleanupPingCommented:
jasminekwok:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now