|
Search Tech-Forums - link takes you to our Forum's search page. Note: The following is only a text archive! To view the actual forum discussion, please visit our website at http://www.tech-forums.net Pages:1 Converting from hexa to decimal(Click here to view the original thread with full colors/images)Posted by: caughtbehind 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 Posted by: Chase 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-:: Posted by: Chankama 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 Posted by: jaeusm [QUOTE]I found the number as well, but I have yet to decipher the ">>2" thing[/QUOTE] ">>" 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[/CODE] Edit: Chankama beat me to it :) Posted by: wilsoniya 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: [url]http://en.wikipedia.org/wiki/Bitwise_shift#Shifts_in_C.2C_C.2B.2B.2C_and_Java[/url] 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. vBulletin Copyright ©2000 - 2003, Jelsoft Enterprises Limited. PPC Management vB Easy Archive Final - Created by Xenon |