Thanks and Regards, Amit Taneja
Originally posted by sweety do:
hey amit,
here adding 1 means using OR operation..hence OR operation for 0101 +1
is
0101
+ 0001
_____________________
0101
1+1 does not give a carry 1 into next bit
hope this helps,
sweety
Thanks and Regards, Amit Taneja
i = -10 is a negative number..so take 2's complement of the number..
that is 2's complement of all the 32 bits of 10 (0000....1010)...the 2'complement is (1111....0101)
How ?
Thanks and Regards, Amit Taneja
Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
(1)111 1111 1111 1111 1111 1111 1111 0110
Now we need to convert 111 1111 1111 1111 1111 1111 1111 0110
to decimal right ? so how will we get 3 after shifting.
Piyush Jain<br /> <br />Being happy doesn't mean everything's perfect. It means you've decided to see beyond the imperfections.
Thanks and Regards, Amit Taneja
Shubhada
Originally posted by sweety do:
i am not clear with one thing ::what does adding
0011
0101
0001
0111
Originally posted by shiva rao:
Hi All,
I am getting 3. But I still don't get -1
Thanks!
shiva rao
Originally posted by Steven Bell:
Why would you get -1?
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Cheers,<br />Jay<br /> <br />(SCJP 1.4)<br />Heights of great men were not achieved in one day, they were toiling day and night while their companions slept.
Shubhada
Originally posted by shubh hadan:
Thanks Jay,
U helpd me to remove my confusion.
hi shiva ,
see
the Q is -10>>2=?
Now 1st start with 10.
In binary 10 is represented as;
0000 0000.......0000 1010
Now do 2's complement
0000 0000.......0000 1010
+ ^1 (^ start inverting)
--------------------------------------
1111 1111 ......1111 0110 (-10 in decimal)
shift to right by 2.
this will give;
1111 1111.......1111 1101
(This is actually no. -3 in the binary form)
Once again do 2's complement ;
1111 1111.........1111 1101
+ ^1
-------------------------------------
0000 0000.........0000 0011 (3 in decimal)
means the ans is -3.
Am i right friends?
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Yeah, but does being a ninja come with a dental plan? And what about this tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|