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

So do you understand Twos Complement yet? You never responded to your previous questions, so we don't know if you actually understood the answers.

Henry

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

Originally posted by Anto telvin Mathew:

about the first question

how can i shift it using -1 ?

When you shift an int by an amount, only the 5 lower bits (of the amount) are used. (for long, it is the 6 lower bits)

And what is the 5 lower bits for -1? Well, since you now understand Twos complement, can you tell me what the 5 lower bits for -1 is?

Henry

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

Originally posted by Anto telvin Mathew:

ok buddy

if the number is other than -1 like 134>>-2,-3 and so on then what to do.

Same thing. What is the bit pattern (using Twos Complement to figure out) of -2 or -3? What is the 5 lower bits of that value / pattern?

Henry

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

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 Mathew<br />Many of the life failures are people who did not realize how close they were to success when they give up. EDISON

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

304 << 26 = 0101 0000 0000 0000 0000 0000 0000 0000

Notice that some of the bits have fallen off. Anyway, I leave it up to you to convert this result back to decimal.

Henry

Originally posted by Anto telvin Mathew:

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

Same as the last one. Start with 340 in binary...

340 = 0000 0000 0000 0000 0000 0001 0101 0100

Shift it left by 31

340 << 31 = 0000 0000 0000 0000 0000 0000 0000 0000

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

Henry

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.

Henry

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

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

1*2^31 + 1*2^30 +1*2^29 right

then why here we didn't take the two's compliment

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 ]

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

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 ?

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

thanks

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.

Joanne

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |