?
Solved

Difference between storing bytes in C and Java

Posted on 2003-03-24
8
Medium Priority
?
266 Views
Last Modified: 2010-03-31
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
Comment
Question by:jasminekwok
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 

Expert Comment

by:bhayzone
ID: 8200554
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
 
LVL 9

Expert Comment

by:yongsing
ID: 8200572
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
 

Accepted Solution

by:
bhayzone earned 40 total points
ID: 8200586
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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 

Author Comment

by:jasminekwok
ID: 8200588
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
 
LVL 9

Expert Comment

by:yongsing
ID: 8200636
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
 
LVL 24

Expert Comment

by:sciuriware
ID: 8201017
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 8201530
Also bytes are signed in Java
0
 

Expert Comment

by:CleanupPing
ID: 9058507
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month11 days, 11 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question