posted 17 years ago
first you need to convert int (decimals) to binary
the way to do it is to add up the binary positions to make
up the interger you want
for example
if we have 128, and we want to know its binary equivalent
1000 0000 is the binary equivalent
each position in the binary representation stands for a decimal
value, so starting from the right and going to the left
128 64 32 16 8 4 2 1
you notice that we have 8 numbers, corresponding to the 8 binary
positions.
so we find that 128 is actually 1000 0000
if we want for example 4 then it will be 0000 0100
if we want 10 , it will be 0000 1010
as so on.
the way to do it is to add up the binary positions to make
up the interger you want
for example
if we have 128, and we want to know its binary equivalent
1000 0000 is the binary equivalent
each position in the binary representation stands for a decimal
value, so starting from the right and going to the left
128 64 32 16 8 4 2 1
you notice that we have 8 numbers, corresponding to the 8 binary
positions.
so we find that 128 is actually 1000 0000
if we want for example 4 then it will be 0000 0100
if we want 10 , it will be 0000 1010
as so on.
posted 17 years ago
u devide the number by 2 and keep the remainder on the right side
and 128/2 = 64 and remainder 0
now again devide 64 by 2 and put teh remainder on the right as done below .. keep on deviding till u get 0 in the last
now arrange the digits from bottomto top and u get the answer
21280

640

320

160

80

40

20
_
11
_
0
so the answer is 100000000
and 128/2 = 64 and remainder 0
now again devide 64 by 2 and put teh remainder on the right as done below .. keep on deviding till u get 0 in the last
now arrange the digits from bottomto top and u get the answer
21280

640

320

160

80

40

20
_
11
_
0
so the answer is 100000000
shabbir zakir
Ranch Hand
Posts: 183
posted 17 years ago
thanks for the explanation.
i don't understand one thing .
rose says that the binary equilant of 4 is
0000 0100
but you divide 4 by 2 you get
and keep the remainder right hand side we get 0010
i don't understand one thing .
rose says that the binary equilant of 4 is
0000 0100
but you divide 4 by 2 you get
and keep the remainder right hand side we get 0010
posted 17 years ago
Maybe I can help.
the >> and >>> symbols are bitwise shift to the right
you take the number, in this case 128, and convert to binary, so:
1000 0000
Then you move all the digits to the right either 1 >> or 2 >>> spaces.
Anything that "falls off" the end you ignore, and you put zeros in the place of anything that "comes on" to the byte, so:
1000 0000 >> 0100 0000
1000 0000 >>> 0010 0000
Then you just convert back.
so, 128 >> 64 and 128 >>> 32.
In this case, the answer would be A.
Hope this helps.
(someone please correct if I have made a mistake somewhere.)
the >> and >>> symbols are bitwise shift to the right
you take the number, in this case 128, and convert to binary, so:
1000 0000
Then you move all the digits to the right either 1 >> or 2 >>> spaces.
Anything that "falls off" the end you ignore, and you put zeros in the place of anything that "comes on" to the byte, so:
1000 0000 >> 0100 0000
1000 0000 >>> 0010 0000
Then you just convert back.
so, 128 >> 64 and 128 >>> 32.
In this case, the answer would be A.
Hope this helps.
(someone please correct if I have made a mistake somewhere.)
Matthew Jones
Ranch Hand
Posts: 68
posted 17 years ago
PS. actually, I tested, and >> and >>> did exactly the same think, so the answer would be A and B.
Originally posted by Matthew Jones:
Maybe I can help.
the >> and >>> symbols are bitwise shift to the right
you take the number, in this case 128, and convert to binary, so:
1000 0000
Then you move all the digits to the right either 1 >> or 2 >>> spaces.
Anything that "falls off" the end you ignore, and you put zeros in the place of anything that "comes on" to the byte, so:
1000 0000 >> 0100 0000
1000 0000 >>> 0010 0000
Then you just convert back.
so, 128 >> 64 and 128 >>> 32.
In this case, the answer would be A.
Hope this helps.
(someone please correct if I have made a mistake somewhere.)
PS. actually, I tested, and >> and >>> did exactly the same think, so the answer would be A and B.
shabbir zakir
Ranch Hand
Posts: 183