uint256 bits() seems to be scanning from right to left rather than left to right #4972

issue donovanhide opened this issue on September 24, 2014
  1. donovanhide commented at 4:38 PM on September 24, 2014: none

    https://github.com/bitcoin/bitcoin/blob/master/src/uint256.h#L258-L259 https://github.com/bitcoin/bitcoin/blob/master/src/uint256.cpp#L204-L216

    I might be going a little insane, but I'd assume to find the highest set bit in a uint256 you'd need to start at the highest bit of the leftmost uint32 and progress right. That is:

        for (int pos = 0; pos < WIDTH; pos++) {
    
  2. theuni commented at 5:17 PM on September 24, 2014: member

    Least significant limbs come first. So you're looking for the highest bit at the last non-zero position.

  3. donovanhide commented at 5:22 PM on September 24, 2014: none

    I can see that fits with the compact format, but does it make sense in the context of the division operator?

    https://github.com/bitcoin/bitcoin/blob/master/src/uint256.cpp#L95-L96

  4. sipa commented at 5:25 PM on September 24, 2014: member

    The number represented by a uint256 with uint32_t pn[8] = {a,b,c,d,e,f,g,h} represents value: a + 2^32_b + 2^64_c + 2^96_d + 2^128_e + 2^160_f + 2^192_g + 2^224*h.

    All uint256 operators work on this format.

  5. laanwj closed this on Sep 25, 2014

  6. laanwj commented at 7:37 AM on September 25, 2014: member

    Not an issue, closing.

  7. bitcoin locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-20 06:55 UTC