MS calculator on windows 7 has a "programmers" mode. When I type in (in binary): 1111111111111111111111111111111111111111111111111111111111111111
and t开发者_如何学JAVAhen click "Dec", the binary turns into -1. When I click Oct, the value turns into 1777777777777777777777
However, whenever I use an online converter, it doesn't work. I need to know how the calculator is doing this so I can emulate it in c++.
It is using 64 bit two's complement notation. Basically, when you add one to 2^63 - 1
, it overflows and you get -2^63
. Wikipedia for more detail
Ever heard of 2s complement? It all depends (logically on the length of the binary number. Hardware lets you work with one word at a time, however.
It's doing two's complement when you switch it to decimal. In octal form, it is doing a straight conversion.
精彩评论