Understanding Base-2 (Binary)
The standard numbering system humans use is Base-10 (Decimal), which relies on ten digits (0 through 9). Computers, however, operate using transistors that only have two states: On or Off. Because of this hardware limitation, computers process all data using Base-2 (Binary), which relies on only two digits: 0 and 1.
Binary Arithmetic vs. Bitwise Logic
Arithmetic
This works exactly like normal math, but numbers carry over at 2 instead of 10. For example, 1 + 1 does not equal 2. Instead, it equals 10 (which represents "2" in binary).
Bitwise Logic
Instead of treating the inputs as whole numbers, bitwise logic compares them digit by digit (bit by bit). This is heavily used in low-level programming, subnetting, and encryption.
Common Bitwise Operations Explained
- AND (&): The output bit is 1 only if both input bits are 1. Otherwise, it is 0.
- OR (|): The output bit is 1 if at least one of the input bits is 1.
- XOR (^): (Exclusive OR) The output bit is 1 if the input bits are different. If they are the same (both 0 or both 1), the output is 0.
- NOT (~): Also known as a bitwise inversion. This simply flips every 0 to a 1, and every 1 to a 0.