# Explaination Required.

Nikhil Nagrani
Greenhorn
Posts: 24
Hey could anybody please explain me the output of the following codes and how hexadecimal string representation works.Thanks.

1)

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

Here is the output of this program:
b = 0xf1

Rob Spoor
Sheriff
Posts: 20707
68
Welcome to the Ranch!

Please UseCodeTags next time. I've added them for you this time. Don't forget to keep the indentation (which I also added).

Nikhil Nagrani
Greenhorn
Posts: 24
Ya sure...from the next time i will keep that in mind...

Henry Wong
author
Marshal
Posts: 21725
85
Nikhil Nagrani wrote:
1)

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.

Henry

Nikhil Nagrani
Greenhorn
Posts: 24
Hey Henry,

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..

Henry Wong
author
Marshal
Posts: 21725
85
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.

Henry

fred rosenberger
lowercase baba
Bartender
Posts: 12229
36
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?

Nikhil Nagrani
Greenhorn
Posts: 24
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.

Henry Wong
author
Marshal
Posts: 21725
85
• 1
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.

Henry

Nikhil Nagrani
Greenhorn
Posts: 24
Hey..thanks henry...