Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Byte operation

Status
Not open for further replies.

drkestrel

MIS
Sep 25, 2000
439
GB
I have an integer, for which I would like to interpret as an overflow value of the first 2 bytes

I tried
Code:
int myInt= 99999999999999999999999999999999999;
int first2Byte = myInt & 0xFFFF;
System.out.println (first2Byte);

However, the value seems too small to be true!!

What is the correct way of doing this?
 
how did u even get this to compile??? 99999999999999999999999999999999999 is WAY too big for an int
 
Hi,

Yes that overflows maxint.
What do you mean with too small value? Let's take an example:


int myInt= 210000000;
int first2Byte = myInt & 0xFFFF;
System.out.println (first2Byte);

Gives you result 22656
which is 101100010000000 as binary

So the calculation goes like this:

1100100001000101100010000000 <- 210000000 as bin
0000000000001111111111111111 & <- FFFF (65535) bin
-----------------------------
0000000000000101100010000000

= 22656

I hope this made the situation clearer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top