Computer ยท Chapter 02

๐Ÿ”ข 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

๐Ÿ“Š Hex quick reference โ€” SSC/CCC exam

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, ASCII, Unicode

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

Animation
NUMBER SYSTEM VISUAL โ€” CLICK A SYSTEM TO EXPLORE BINARY Base 2 Digits: 0, 1 0 = 0000 1 = 0001 2 = 0010 3 = 0011 5 = 0101 10 = 1010 15 = 1111 255 = 11111111 Used: Computer hardware All data is binary inside OCTAL Base 8 Digits: 0-7 8 (dec) = 10 (oct) 9 (dec) = 11 (oct) 15 (dec) = 17 (oct) 64 (dec) = 100 (oct) 255 (dec) = 377 (oct) Shortcut: group binary in sets of 3 bits 011 101 = 35 (oct) Used: Unix permissions chmod 755 = rwxr-xr-x DECIMAL Base 10 Digits: 0-9 Our everyday system 10^0 = 1 (units) 10^1 = 10 (tens) 10^2 = 100 (hundreds) 425 = 4x100+2x10+5x1 Human-friendly system Bridge between binary and human thinking HEXADECIMAL Base 16 Digits: 0-9, A-F A=10, B=11, C=12 D=13, E=14, F=15 FF = 255 (decimal) 1A = 26 (decimal) FF in binary = 11111111 Used: HTML colors #FF5733 = R:255 G:87 B:51 MAC addresses, memory Shortcut: group binary in sets of 4 bits CLICK A NUMBER SYSTEM Number systems are different ways to represent the same value. 13 in decimal = 1101 in binary = 15 in octal = D in hex.

Hex is compact โ€” 2 hex digits = 1 byte = 8 binary digits. That is why programmers prefer hex.

๐Ÿ’ป

Live Number Converter

Interactive
Binary101010
Octal52
Decimal42
Hexadecimal2A
Practice (SSC/CCC): Convert (11010101)โ‚‚ to decimal and hexadecimal.
Binary 11010101 โ†’ Decimal:
Position: 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.
Practice (O-Level): What is 1's complement and 2's complement? Why does a computer use 2's complement?
1's Complement: Flip all bits (0โ†’1, 1โ†’0).
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.
โ†
Previous
Computer Basics