i want to know how we are calculating 127>>-1 .i know if it is 1 on the right hand side we can do it by dividing first by second .but what is happening here if it a negative value .please help

one more question how can i do 127>>>4 and -128>>>3 also with some negative values

thanks in advance

Anto Telvin Mathew<br />Many of the life failures are people who did not realize how close they were to success when they give up. EDISON

sorry dear actually what happened is that i am not able to know how to ask another question in the same topic that is why i understood whatever you told i know two's complement .but when negative number came no idea what to do

Originally posted by Anto telvin Mathew: yup i got it what is happening if i use >>> ?

In a ">>" right shift, the high order bit remains unchanged during the shift. In a ">>>" right shift, the high order bit is cleared -- mean a zero is shifted into it.

Henry

Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113

posted

0

thanks dear

Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113

posted

0

hi while doing this i have some problem ? 340<<-6 after two's compliment i got like this 1111 1010 and i took the first 5 lower bits and in decimal it is 26 . when i multiply 340*2 raised to 26 manually i am getting value 22817013760 .but the output compiler is showing to me is 1342177280

i want to know why ?if am wrong in doing please help me out

thanks

Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113

posted

0

and if am using 340<<-1 i am getting 0 as output. but it is multiplication right 340*2 raised to 31 how ?

when i multiply 340*2 raised to 26 manually i am getting value 22817013760 .but the output compiler is showing to me is 1342177280

Keep in mind, that shifting left is *not* the same as multiplying by two. Multiplying by two is just a technique that some teachers use to get to the "answer" -- which in my opinion... well, I'll get to that next.

Shifting left is... well... shifting left. To envision it, you need to see it in binary. So, lets start with 340:

340 = 0000 0000 0000 0000 0000 0001 0101 0100

If you shift this left by 26, you will need to actually shift it left by 26. Also note that an int can only hold 32 bits, so when you shift left, stuff "falls off" on the left side.

So... Shifting left by 26 bits, will add 26 zeros on the right, move the lower order bits up, and 26 of the higher order bits will "fall off"....

This will mean that all but the LSB has "fallen off", with the former LSB now being the MSB. Anyway, this result is much easier to convert back to decimal...

Keep in mind, that shifting left is *not* the same as multiplying by two. Multiplying by two is just a technique that some teachers use to get to the "answer" -- which in my opinion... well, I'll get to that next.

Oops, almost forgot about my first point. If your school offers a course in assembly language, I highly recommend that you take it. And when you do, take it seriously, even though it will be unlikely you will be coding in it professionally.

Assembly language is the best way to understand the architecture of the computer, particularly shifting techniques -- and you won't need these silly analogies like "shifting left is like multiplying by two" anymore.

Originally posted by Anto telvin Mathew: thanks dear

Oh.... And please *don't* call me "dear". Only my wife does that -- and I don't even like it when she does it.

Henry

Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113

posted

0

yup i am getting the compiler answer as output

thanks

Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113

posted

0

if i using 340<<-6 i am getting 1342177280 ok and if i use -340<<-6 can i write directly the answer by putting a negative sign without checking anything. is it true

Originally posted by Anto telvin Mathew: if i using 340<<-6 i am getting 1342177280 ok and if i use -340<<-6 can i write directly the answer by putting a negative sign without checking anything. is it true

Well, what happens when you try it? You have the techniques to try it out yourself.

Henry

Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113

posted

0

nope i have one doubt if we are left shifting that -340 by 26 that 26 bit are filled by 0 or 1 ?

Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113

posted

0

one more problem 670<<-4 ie 670<<28 670 is 0000 0000 0000 0000 0000 0010 1001 1110

if left shifting it will get 1110 0000 0000 0000 0000 0000 0000 0000

You did (there was just nothing extra that needs to be done). Twos complement for positive numbers behaves the way that you already know. It's the negative numbers that needs the special handling.

Henry [ September 10, 2008: Message edited by: Henry Wong ]

Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113

posted

0

i am confused let me try it with examples .if i am not getting it i will come back again ok

It's the negative numbers that needs the special handling.

BTW, this "special handling" is only for the developer. It is needed to convert negative numbers from binary to decimal, and vice-versa. A computer operates completely in binary, and doesn't need to deal with decimals during calculations.

Henry

Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113

posted

0

Hi i am working out examples and i halt here i am doing this one 440 <<12 i got it correctly

but when i am doing -440<<12 i got wrong

i done like this

1. 440 = 0000 0000 0000 0000 0000 0001 1011 1000 and for -440 i invert it 1111 1111 1111 1111 1111 1110 0100 0111 then i add one 1111 1111 1111 1111 1111 1110 0100 1000 now this is -440 right

so i shifted 12 bits and got 1111 1111 1110 0100 1000 ok remaining bits are 0 or 1 after this what to do ?

Again, what happened when you tried it? Try it with simplier numbers.

BTW, I don't know why you are stuck at this. All the shifting examples shown so far, showed you whether it was a zero or one.

Henry

Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113

posted

0

thanks i got it clearly

Anto Telvin
Ranch Hand

Joined: Aug 12, 2008
Posts: 113

posted

0

hi i posted this question already.but not getting a good answer .so i am again posting it here .i want to know how i can convert a floating point value to IEEE floating point standard for eg: 2.25

they represent it like this s e m 0 1000 0000 001 0000 0000 0000 0000 0000 but i don't know how to do that please help

Originally posted by Anto telvin Mathew: hi i posted this question already.but not getting a good answer .so i am again posting it here

Don't do this. A conversation has started there so continue it in there, otherwise you may end up wasting peoples time giving answers that have already been given.