Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » Converting from hexa to decimal
Closed Thread
Old 02-22-2007, 05:58 PM   #1 (permalink)
 
Newb Techie

Join Date: Feb 2007

Posts: 1

caughtbehind

Default Converting from hexa to decimal

I found this on the facebook website - what do you think is the result of this conversion

{ (0xFACEB00C >> 2) in decimal format } @ facebook.com

I know 0x is the symbol for Hexadecimal, but what does ">> 2" do?

Converting FACEB00C into decimal gives 4207849484 - but I'm pretty sure thats not the solution
caughtbehind is offline  
Old 02-22-2007, 09:05 PM   #2 (permalink)
Chase's Avatar
 
CECS Major

Join Date: Jul 2005

Location: Louisville, KY

Posts: 387

Chase is on a distinguished road

Send a message via MSN to Chase Send a message via Yahoo to Chase Send a message via Skype™ to Chase
Default

I found the number as well, but I have yet to decipher the ">>2" thing...this is very interesting and rest assured I will post here if I ever figure it out...

::-Chase-::
Chase is offline  
Old 02-22-2007, 09:45 PM   #3 (permalink)
Chankama's Avatar
 
Monster Techie

Join Date: Jan 2005

Location: Canada

Posts: 1,522

Chankama will become famous soon enough

Default

Bit shift operation. In this case by 2 positions. Which is analogous to dividing the number by 4..

e.g. 0xC >> 2 = 0x1100 >> 2 = 0x11 = 3

or 0xC >> 2 = 12 /4 = 3
Chankama is offline  
Old 02-22-2007, 09:49 PM   #4 (permalink)
 
Software Developer

Join Date: Mar 2006

Location: Columbus, OH

Posts: 569

jaeusm is on a distinguished road

Default

Quote:
I found the number as well, but I have yet to decipher the ">>2" thing
">>" is the bitwise right shift operator. In this case, it means shift 2 bits to the right, or knock the two right-most (least significant) bits off. For instance, a right shift of 2 bits applied to the value 0xF is 0x3.
Code:
0xF = 1111 (binary)
1111 >> 2 = 0011 = 3
Edit: Chankama beat me to it
jaeusm is offline  
Old 03-06-2007, 09:44 PM   #5 (permalink)
 
Newb Techie

Join Date: Mar 2007

Posts: 1

wilsoniya

Default

The behavior of >> varies from language to language. In C and Java, >> is the arithmetic right shift operator. I believe the previous two posts by jaeusm and Chankama have almost covered how >> is handled.

You both are correct under intuitive circumstances. In A >> B, you were considering A to be an unsigned integer. If we allow A to be signed, we will run into problems. Take the previous example:

0xF = 1111

If 0xF is unsigned:
1111 >> 2 = 0011
or equivalently:
15 >> 2 = 3.

Unfortunately, C and Java handle arithmetic right shift differently. It seems C forces the number being shifted to be unsigned. Java uses the 'correct' definition of arithmetic right shift and propagates the most significant bit in the result (known as sign extension):

1111 >> 2 = 1111
equivalently in decimal:
-1 >> 2 = -1

or using a different example:
1100 >> 1 = 1110
equivalently in decimal:
-4 >> 1 = -2

Verify: http://en.wikipedia.org/wiki/Bitwise...2B.2C_and_Java

Note I am using 2's complement for the representation of the signed integers.

If you ask me, 0xfaceb00c >> 2 is an idiotic thing for the facebook recruiting team to use as an email address. I know they're trying to be clever, but honestly, I hope the engineers exercise a higher degree of finite precision in their daily work than they do in describing their obscure email addresses.
wilsoniya is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On