What are the first 32 bits of the fractional part of this float?

I am considering the following pseudo-code SHA256 on Wikipedia.

In particular, I look at the next section.

//Initialize variables
//(first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19):
h0 := 0x6a09e667

I am trying to figure out how h0 was created. I know from the comment that this should be the fractional part of the square root of 2. I believe that I can get the fractional part of the square root of 2 by entering the following. All the following code is from python replication.

>>> math.modf(math.sqrt(2))[0]
0.41421356237309515

The top of the file indicates that the declaration of all constants is Big Endian. I know that my environment is Small Endian, because I print.

>>> import sys
>>> sys.byteorder
'little'

So, according to my manual manipulation of the hex value in h0, the Little Endian representation should be 0x67e6096a.

>>> int(0x67e6096a)
1743128938

. , . , 32 . , - 0.41421356237309515 (float) 1743128938 (int), , . , 32 ? Python , .

.

+5
3

; , . , . , struct . , ; hex , :

>>> hex(int(math.modf(math.sqrt(2))[0]*(1<<32)))
'0x6a09e667'
+8
  • Windows, sqrt (2) (1.4142135623730950488016887242097).
  • (0.4142135623730950488016887242097)
  • 2 ^ 32 (1779033703.9520993849027770600526)
  • (6A09E667)

Voila. ( OP , Python, , .)

+6
>>> math.sqrt(2).hex()
'0x1.6a09e667f3bcdp+0'

, :

>>> '0x'+math.sqrt(2).hex().split('.')[1][:8]
'0x6a09e667'
+3

All Articles