Binary & Hexadecimal Programmer's Calculator: Convert and calculate across Binary, Hexadecimal, Octal, and Decimal with bitwise operations (AND, OR, XOR, NOT, bit shifts) and interactive 32-bit switch grid.
Computer Architecture & Binary Radix Systems
In digital computing, all processors operate on transistors switching between electrical voltages representing binary states ($0$ and $1$). Because reading long sequences of binary bits is unwieldy for software engineers, radix systems with base powers of two are utilized:
- Binary (Base-2): Uses symbols ${0, 1}$. Every position represents a power of $2$ ($2^0, 2^1, 2^2, dots$).
- Octal (Base-8): Uses symbols ${0, 1, 2, 3, 4, 5, 6, 7}$. Every octal digit represents exactly $3$ binary bits ($2^3 = 8$). Standard in Unix file permissions (`chmod 755`).
- Hexadecimal (Base-16): Uses digits ${0-9}$ and letters ${A, B, C, D, E, F}$. Every hex character represents exactly $4$ binary bits (a nibble, $2^4 = 16$), making two hex characters equal to exactly one 8-bit byte ($0x00$ to $0xFF$).
Bitwise Logic Operations
Bitwise operators manipulate integer representations at the individual bit level:
- AND ($&$): Result bit is $1$ only if both corresponding bits are $1$. Used for bitmasking and flag extraction.
- OR ($|$): Result bit is $1$ if either bit is $1$. Used for setting configuration flags.
- XOR ($oplus$): Result bit is $1$ if bits are strictly different. Used in cryptography, parity calculations, and register zeroing (`XOR EAX, EAX`).
- NOT ($sim$): Inverts every bit ($1 to 0$, $0 to 1$).
- Logical Left Shift ($ll$): Shifts bits left by $k$ positions, equivalent to multiplying by $2^k$.
- Logical Right Shift ($gg$): Shifts bits right by $k$ positions, equivalent to integer division by $2^k$.
Two's Complement Signed Integer Representation
Modern microprocessors represent negative integers using Two's Complement. In a 32-bit signed integer, the most significant bit (MSB, bit 31) acts as the sign bit ($0$ for positive, $1$ for negative). To negate a number in two's complement:
$$text{Two's Complement}(x) = (sim x) + 1$$