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

后端 未结 3 1267
遇见更好的自我
遇见更好的自我 2021-02-05 21:20

I am looking at the following SHA256 pseudocode on wikipedia.

Specifically, I am looking at the following section.

//Initialize variables
//(first 32 bits          


        
3条回答
  •  粉色の甜心
    2021-02-05 22:25

    Endianness does not matter for hexadecimal constants; each digit is a nibble, with the least significant nibble last. It does matter if you deal with differing size pointers. If you do need to use byte orders, the struct module can help. Anyhow, you've retrieved the fractional part just fine; converting it to hex is easily done by simply multiplying and truncating, so we get an integer:

    >>> hex(int(math.modf(math.sqrt(2))[0]*(1<<32)))
    '0x6a09e667'
    

提交回复
热议问题