0x9e3779b9 golden number

i'm trying to understand a constant 0x9e3779b9 what kind of data is this? it's not binary, not decimal, what is this?

it's a constant used on the TEA algorithm it says it's derived from the golden number but the golden number is 1.618?

-
Do you mean the number format or how did they come up with the value? –  Matthew Whited Mar 30 '11 at 13:17
what about the format? i've never seen it... i read that the value is from (1 + √5)/(2^31) but after i try it the result is 2654435769.4972302964775847707926? –  pandr01d Mar 30 '11 at 13:19
In most C style languages `0x` is a prefix for a hexadecimal number. I'm wondering if that is the hex format for the floating point representation of the golden number. Of course that would beg the question of why store an FP value as an integer? Perhaps they optimized the implementation of the TEA algorithm to work with integers instead of floating point values? –  Berin Loritsch Mar 30 '11 at 13:21
It is en.wikipedia.org/wiki/Hexadecimal format. –  TZHX Mar 30 '11 at 13:22
i think they store it as integer because later it would be multiplied by some other number –  pandr01d Mar 30 '11 at 13:28

As others have said, the constant is an integer in hexadecimal form. Specifically, it is a 32-bit integer in hexadecimal form. If the constant is a signed integer, then 0x9e3779b9 is negative 1640531527 decimal in two's complement form; therefore, it may be a scaled integer fraction that has been adjusted to deal with non-integral of 2 related problems.

Two's complement negative to positive conversion in hex

``````0x9e3779b9 ⊕ 0xffffffff + 0x00000001 = 0x61C88647 = 1640531527 in decimal
``````

or using the 1's complement operator ~ in the C family of languages

``````~0x9e3779b9 + 0x00000001 = 0x61C88647 = 1640531527 in decimal
``````

Two's complement negative to positive conversion in binary

``````10011110001101110111100110111001 ⊕ 11111111111111111111111111111111 + 00000000000000000000000000000001 =  01100001110010001000011001000111 = 1640531527 in decimal
``````
-

I think this StackOverflow question answers it:

http://stackoverflow.com/questions/4948780/magic-numbers-in-boosthash-combine

Essentially, it is a "golden number" for hash functions, and it being an integer is quicker to calculate.

The notation `0x` is for a hexadecimal number, or base 16. The benefit of a base 16 number is that each pair of digits represents one byte exactly. Given a little practice, you can almost see the bit pattern in your mind, assuming you've ever worked with binary numbers.

-
I had just found something similar +1 –  Matt Ellen Mar 30 '11 at 13:31
okay i guess i have to understand the hash function first –  pandr01d Mar 30 '11 at 13:45
@Berin - is there a reason for this particular number? You presumably just need an irregular set of 0 and 1. Is the golden ratio link just arbitrary or is there some deeper mathematical logic? –  Martin Beckett Mar 30 '11 at 20:08
People with better understanding of hash algorithms would be better suited for that answer. My understanding of this "magic number" is that it is mathematically random, but that's where it ends. –  Berin Loritsch Mar 30 '11 at 22:53
In the link I provided, the selected answer says that the number is derived from the golden ratio. The answer also has the math that created the answer. –  Berin Loritsch Mar 30 '11 at 23:39