๐ข Number Systems
Binary, octal, decimal, hexadecimal and conversions.
๐ข How Computers Count
Computers only understand 0 and 1 (binary). All data โ text, images, sound โ is stored as binary numbers. We use different number systems to work with these.
4 number systems:
โข Binary (Base-2) โ digits: 0,1. Used internally by all computers.
โข Octal (Base-8) โ digits: 0-7. Used in Unix file permissions.
โข Decimal (Base-10) โ digits: 0-9. Our everyday number system.
โข Hexadecimal (Base-16) โ digits: 0-9, A-F. Used in colors (#FF5733), memory addresses, MAC addresses.
Conversions to remember:
Binary โ Decimal: multiply each bit by 2^position (right to left starting from 0)
Example: 1011 = 1ร8 + 0ร4 + 1ร2 + 1ร1 = 8+0+2+1 = 11
Decimal โ Binary: repeatedly divide by 2, read remainders bottom-up
Example: 13 รท 2 = 6 R1, 6 รท 2 = 3 R0, 3 รท 2 = 1 R1, 1 รท 2 = 0 R1 โ 1101
A=10, B=11, C=12, D=13, E=14, F=15
Hex FF = 15ร16 + 15 = 240+15 = 255 (maximum value of 1 byte)
Web colors: #RRGGBB in hex. #FF0000 = pure red. #00FF00 = pure green. #0000FF = pure blue. #FFFFFF = white. #000000 = black.
Binary to Hex shortcut: Group binary in 4 bits. Each group = 1 hex digit.
Example: 10111010 โ 1011 1010 โ B A โ BA in hex.
BCD (Binary Coded Decimal) โ each decimal digit stored as 4-bit binary. 9 = 1001 in BCD. Used in calculators, digital clocks.
ASCII (American Standard Code for Information Interchange) โ 7-bit code. 128 characters. A=65, a=97, 0=48, Space=32.
Extended ASCII โ 8-bit (256 characters).
Unicode (UTF-8, UTF-16) โ supports ALL world languages. UTF-8 = 1 to 4 bytes per character. Standard for the internet.
EBCDIC โ IBM's older encoding for mainframes.
Number System Converter โ Live
AnimationHex is compact โ 2 hex digits = 1 byte = 8 binary digits. That is why programmers prefer hex.
Live Number Converter
InteractivePosition: 7 6 5 4 3 2 1 0
Bit: 1 1 0 1 0 1 0 1
Value: 128 64 0 16 0 4 0 1
Sum: 128 + 64 + 16 + 4 + 1 = 213
Binary 11010101 โ Hexadecimal:
Group in 4 bits: 1101 | 0101
1101 = 13 = D
0101 = 5
Answer: D5 (or 0xD5)
Verification: D5 hex = 13ร16 + 5 = 208 + 5 = 213 โ
Shortcut: Binary โ Hex is the easiest conversion. Always group 4 binary digits = 1 hex digit.
Example: 0110 โ 1001 (1's complement)
2's Complement: 1's complement + 1.
Example: 0110 โ 1001 + 1 = 1010 (2's complement)
Why computers use 2's complement for negative numbers:
โข It allows subtraction using addition circuits (simpler hardware)
โข Only ONE representation of zero (unlike 1's complement which has +0 and -0)
โข Arithmetic operations work naturally
โข Example: To compute 5 - 3:
5 = 0101
-3 in 2's complement: 3=0011 โ flip=1100 โ +1=1101
0101 + 1101 = 10010 โ drop carry โ 0010 = 2 โ
2's complement is used in virtually all modern processors for signed integer arithmetic.