posted 17 years ago

hi. this is a loaded qustion:

what is a "most significant bit"? least sig bit?

what does is meant when u say "unsigned"?

plese give examples of binay arithmetic involving the above .

thanks

what is a "most significant bit"? least sig bit?

what does is meant when u say "unsigned"?

plese give examples of binay arithmetic involving the above .

thanks

posted 17 years ago

HI,

The left-most bit is the sign bit. If the left most bit is 1 then the number is negative else the number is positive.

This left-most bit is the most significant bit.

The right-most bit is the least significant bit.

An un-signed operator >>> means that the most significant bit is always to be filled by 0's.

if you start with a negative binary number...

1111 1010 // and you want to know the value

1. Flip the bits

0000 0101

2. Add 1

0000 0101

+

0000 0001

------------

0000 0110 // this is 6, so the value was -6.

Another shortcut:

start from the rightmost bit(least significant bit).

Just copy everything until you see first "1".Then flip the remaining bits.

The same eg:1111 1010

result:0000 0110

For more examples on shifting refer to RHE book.It has real good examples.

------------------

Cheers,

Deepa

The left-most bit is the sign bit. If the left most bit is 1 then the number is negative else the number is positive.

This left-most bit is the most significant bit.

The right-most bit is the least significant bit.

An un-signed operator >>> means that the most significant bit is always to be filled by 0's.

if you start with a negative binary number...

1111 1010 // and you want to know the value

1. Flip the bits

0000 0101

2. Add 1

0000 0101

+

0000 0001

------------

0000 0110 // this is 6, so the value was -6.

Another shortcut:

start from the rightmost bit(least significant bit).

Just copy everything until you see first "1".Then flip the remaining bits.

The same eg:1111 1010

result:0000 0110

For more examples on shifting refer to RHE book.It has real good examples.

------------------

Cheers,

Deepa

Cheers,<BR>Deepa

mansoor iqbal

Ranch Hand

Posts: 91

posted 17 years ago

thanks deepa. BUT...i thought to find the value u did the following:

1111 0110

---------

7654 3210

=1*2^7+1*2^6+1*2^5+1*2^4+0*2^3 ... and so on......this is surely not 6??

1111 0110

---------

7654 3210

=1*2^7+1*2^6+1*2^5+1*2^4+0*2^3 ... and so on......this is surely not 6??

mansoor iqbal

Ranch Hand

Posts: 91

posted 17 years ago

ok..i have it.....ignore my last question...duh!

posted 17 years ago

Hi Deepa,

Can you please help me out with procedure for evaluating the expression "5 >>> 4" using full 32 bit represention of the int.

I come up to converting decimal 5 to its binary ie 101 after this how this is put in the for of 32 bit int and the make shift of bits.

Also let me know how to convert say -5 to decimal !! please give both least significant bits and complete 32 bit representation.

Thanks in advance.

Shrinivas

Can you please help me out with procedure for evaluating the expression "5 >>> 4" using full 32 bit represention of the int.

I come up to converting decimal 5 to its binary ie 101 after this how this is put in the for of 32 bit int and the make shift of bits.

Also let me know how to convert say -5 to decimal !! please give both least significant bits and complete 32 bit representation.

Thanks in advance.

Shrinivas

Sun Certified programmer for Java2 platform.<BR>Shri_mk@hotmail.com

mansoor iqbal

Ranch Hand

Posts: 91

posted 17 years ago

5>>>4

8421

--------|--------|--------|--------|

00000000 00000000 00000000 00000101

shifting this 4 places to the right wd clearly imply that there are all zeros .. thus the final value after the shift is 0

8421

--------|--------|--------|--------|

00000000 00000000 00000000 00000101

shifting this 4 places to the right wd clearly imply that there are all zeros .. thus the final value after the shift is 0

posted 17 years ago

Hi everyone

Let me tell you one more trick with shifting

you can quickly multiply and divide numbers by a value of 2 i.e.

when you shift left you are multiplying by 2

and vice versa when shifitng right but remember the sign is preserved in case of division i.e. right shift

Let me tell you one more trick with shifting

you can quickly multiply and divide numbers by a value of 2 i.e.

when you shift left you are multiplying by 2

and vice versa when shifitng right but remember the sign is preserved in case of division i.e. right shift

posted 17 years ago

Hi all,

How do you convert a binary number into Hexadecimal and Octal ??

Could someone Please give me a couple of Examples ?

Thanks in Advance.

How do you convert a binary number into Hexadecimal and Octal ??

Could someone Please give me a couple of Examples ?

Thanks in Advance.

posted 17 years ago

Hi Zahid,

I have some notes on Binary/Octal/Decimal/Hexidecimal conversions posted at http://www.janeg.ca/scjp/oper/binhex.html ;

Hope they help.

------------------

Jane Griscti

Sun Certified Programmer for the Javaï¿½ 2 Platform

I have some notes on Binary/Octal/Decimal/Hexidecimal conversions posted at http://www.janeg.ca/scjp/oper/binhex.html ;

Hope they help.

------------------

Jane Griscti

Sun Certified Programmer for the Javaï¿½ 2 Platform

Jane Griscti

SCJP, Co-author Mike Meyers' Java 2 Certification Passport

Zahid, Butt

Ranch Hand

Posts: 100

posted 17 years ago

Thanks Jane.

The site is very Useful.

The site is very Useful.