microsoft / calculator

Windows Calculator: A simple yet powerful calculator that ships with Windows
MIT License
29.47k stars 5.34k forks source link

Implement two's complement switch in the programmer calculator #1823

Open timleg002 opened 2 years ago

timleg002 commented 2 years ago

Goals

I'm currently deciphering a binary protocol, which is binary galore, so this would be helpful, maybe it'd even help explaining the concept to someone.

HolgerStrauss commented 2 years ago

I think that a switch would not be sufficient, because it depends on the word size if a two's complement number is positive or negative. E.g. 0xFFFF seen as a 16 bit number is negative, but seen as a 32 bit number is positive. So the calculator needs to know the intended word size to interpret the number correctly. However, what is confusing is that the calculator uses two's complement for 64 bit numbers already. Just enter hex "FFFFFFFFFFFFFFFF" and the decimal number will suddenly switch from a positive number to "-1" after entering the last "F". This has the notion of a bug.