This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.

The program generates the following output:
536870908
1073741816
2147483632
-32

First, do you know the difference between base 10 and base 16? Second, do you know how shifting works? And finally, do you know what twos complement does?

Those concepts should explain everything in this example. You should start your research there.

I have gone through those concepts but unable to get through these examples(rather this type of hexadecimal notation)......please explain me the same.Thanks..

Nikhil Nagrani wrote:
I have gone through those concepts but unable to get through these examples(rather this type of hexadecimal notation)......please explain me the same.Thanks..

Please explain the confusion that you are encountering, in relation to those concepts -- and hopefully, we can figure out where you went wrong.

Nikhil Nagrani wrote:unable to get through these examples(rather this type of hexadecimal notation)....

What do you mean by "this type of hexadecimal notation"? What other kind is there?

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

Nikhil Nagrani
Greenhorn

Joined: Dec 23, 2010
Posts: 24

posted

0

This is what i can interpret:
Num=0xFFFFFFE
i.e num is 1111 1111 1111 1111 1111 1111 1110
So goin through the loop,after 1st iteration,num should be left shifted by one,so num becomes:
num: 1111 1111 1111 1111 1111 1111 1100
So now how can this be equal to 536870908(1st output)...

I guess i m conceptually wrong somewhere..correct me please.

Nikhil Nagrani wrote:This is what i can interpret:
Num=0xFFFFFFE
i.e num is 1111 1111 1111 1111 1111 1111 1110
So goin through the loop,after 1st iteration,num should be left shifted by one,so num becomes:
num: 1111 1111 1111 1111 1111 1111 1100
So now how can this be equal to 536870908(1st output)...

I guess i m conceptually wrong somewhere..correct me please.

An int is 4 bytes... So, 0xFFFFFFE is binary 0000 1111 1111 1111 1111 1111 1111 1110. And after the shift it becomes binary 0001 1111 1111 1111 1111 1111 1111 1100.