Sign in to follow this  

Endian on windows and java

This topic is 4352 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey I have just begun my client written in c++ with winsock2 sockets. The server though is written in java. When sending the integer 1 from the client to the server, I get the integer 16777216 on the server side. So I'm thinking I have a endian problem. But the thing is that I though windows was Big-Endian and Java also was Big-Endian, so how can this be?

Share this post


Link to post
Share on other sites
Windows does not have an endianness, as far as I know. However, windows will generally be running on an Intel architecture, which is little-endian.

For safety, you should always convert to and from an explicitly known endianness whenever you serialize anything (saving it to disk, sending it over the network, whatever).

John B

Share this post


Link to post
Share on other sites
Quote:
Original post by LizardCPP
So I have to use htons and htonl for everyting large than a byte? Ok but a ascii string is composed out of char:s which are the size of a byte, so they won't have to be converted, do they?

Yep, that's correct.

John B

Share this post


Link to post
Share on other sites
Quote:
Original post by LizardCPP
Ok but a ascii string is composed out of char:s which are the size of a byte, so they won't have to be converted, do they?


Note that the char data type in Java is 16 bits to conform to the Unicode specification. I learned this the hard way. I automatically thought that a char in Java was 8 bits.

GCS584

Share this post


Link to post
Share on other sites

This topic is 4352 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this