开发者

3 * 8 = 18 in c++

Im getting a slight math error in my program, which is causing problems in the rest of it, and i dont get why it is happening. in this part of the class, i did not overload the operators for built in types (i hope). if i did, please show me where

this function is meant to calculate the least number of bits needed to store a the number, which is stored in a deque <uint8_t> value as one value, so 0x123开发者_C百科456 will be stored as {0x12, 0x34, 0x56}, and the output to integer.bits() should be 21

    // all types here are standard, so i dont know whats going on
    unsigned int bits(){
        unsigned int out = value.size() << 3;
        std::cout << out << " " << value.size() << " " << (value.size() << 3) << std::endl;
        uint8_t top = 128;
        while (!(value.front() & top)){
            out--;
            top >>= 1;
        }
        return out;
    }

yet, this part is couting

8 1 8
16 2 16
...

and finally, 
18 3 18

http://ideone.com/zLfz2


3*8 is 24, and in hex that's 0x18. You have std::hex scattered about your code...


Someone has changed your stream to hex and it's printing 24 decimal as 18 hex.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜