2.3. Decimal ↔ Binary Conversion
Table of Contents
Understanding Decimal and Binary Conversion
In networking, devices represent all information as binary. Humans prefer decimal. Being able to move between these two views is essential, especially for topics like IP addressing and subnetting that appear later in the course. This chapter focuses only on how to convert between decimal and binary, and how to read these representations with confidence.
Place Values in Decimal and Binary
Before converting, you must understand place values.
In the decimal system, each position is a power of 10. From right to left, the places are:
| Position (from right) | Power of 10 | Place value |
|---|---|---|
| 0 | $10^0$ | 1 |
| 1 | $10^1$ | 10 |
| 2 | $10^2$ | 100 |
| 3 | $10^3$ | 1000 |
For example, the decimal number 472 means:
$$4 \times 100 + 7 \times 10 + 2 \times 1$$
In the binary system, each position is a power of 2. From right to left, the places are:
| Position (from right) | Power of 2 | Place value |
|---|---|---|
| 0 | $2^0$ | 1 |
| 1 | $2^1$ | 2 |
| 2 | $2^2$ | 4 |
| 3 | $2^3$ | 8 |
| 4 | $2^4$ | 16 |
| 5 | $2^5$ | 32 |
| 6 | $2^6$ | 64 |
| 7 | $2^7$ | 128 |
So a binary number like 1011 means:
$$1 \times 8 + 0 \times 4 + 1 \times 2 + 1 \times 1$$
which equals 11 in decimal.
Important:
Decimal uses powers of 10.
Binary uses powers of 2.
Each binary digit (bit) is worth either its place value or zero.
Converting Binary to Decimal
To convert from binary to decimal, you expand the binary number using powers of 2, then add the values where there is a 1 bit.
Step by step method
- Write down the binary number.
- Label each bit with its place value, starting from the right with $2^0$.
- For each bit that is 1, write down its place value.
- Add all those place values to get the decimal result.
Example 1: Convert $1011_2$ to decimal
Number: 1011
Place values:
| Bit | Place (power) | Value | Contribution |
|---|---|---|---|
| 1 | $2^3$ | 8 | 8 |
| 0 | $2^2$ | 4 | 0 |
| 1 | $2^1$ | 2 | 2 |
| 1 | $2^0$ | 1 | 1 |
Add the contributions: $8 + 0 + 2 + 1 = 11$
So $1011_2 = 11_{10}$.
Example 2: Convert $110010_2$ to decimal
Number: 110010
Label with powers of 2, from right to left:
| Bit | Power | Value | Contribution |
|---|---|---|---|
| 0 | $2^0$ | 1 | 0 |
| 1 | $2^1$ | 2 | 2 |
| 0 | $2^2$ | 4 | 0 |
| 0 | $2^3$ | 8 | 0 |
| 1 | $2^4$ | 16 | 16 |
| 1 | $2^5$ | 32 | 32 |
Add: $32 + 16 + 2 = 50$
So $110010_2 = 50_{10}$.
Rule for binary to decimal:
Decimal value = sum of (bit value) × (corresponding power of 2).
In symbols:
$$N_{10} = \sum_{i=0}^{k} b_i \times 2^i$$
where each $b_i$ is either 0 or 1.
Converting Small Binary Numbers Quickly
For small binary numbers, you can often convert using a mental table. Up to 4 bits:
| Binary | Decimal |
|---|---|
| 0000 | 0 |
| 0001 | 1 |
| 0010 | 2 |
| 0011 | 3 |
| 0100 | 4 |
| 0101 | 5 |
| 0110 | 6 |
| 0111 | 7 |
| 1000 | 8 |
| 1001 | 9 |
| 1010 | 10 |
| 1011 | 11 |
| 1100 | 12 |
| 1101 | 13 |
| 1110 | 14 |
| 1111 | 15 |
In networking, 8 bits (one byte) is a very common size. The place values for 8 bits are especially important.
| Bit position (from right) | Power | Value |
|---|---|---|
| 0 | $2^0$ | 1 |
| 1 | $2^1$ | 2 |
| 2 | $2^2$ | 4 |
| 3 | $2^3$ | 8 |
| 4 | $2^4$ | 16 |
| 5 | $2^5$ | 32 |
| 6 | $2^6$ | 64 |
| 7 | $2^7$ | 128 |
You will see these values again in IP addressing.
Converting Decimal to Binary: Repeated Division Method
To convert decimal to binary, a standard method uses repeated division by 2 and keeps track of the remainders.
Algorithm
- Divide the decimal number by 2.
- Record the remainder (0 or 1).
- Take the quotient and divide it again by 2.
- Repeat until the quotient is 0.
- The binary number is the sequence of remainders read from last to first.
Example 1: Convert $13_{10}$ to binary
Perform divisions:
| Step | Operation | Quotient | Remainder |
|---|---|---|---|
| 1 | $13 \div 2$ | 6 | 1 |
| 2 | $6 \div 2$ | 3 | 0 |
| 3 | $3 \div 2$ | 1 | 1 |
| 4 | $1 \div 2$ | 0 | 1 |
Now read remainders from bottom to top: 1101
So $13_{10} = 1101_2$.
Check by converting back: $8 + 4 + 0 + 1 = 13$.
Example 2: Convert $50_{10}$ to binary
Divisions:
| Step | Operation | Quotient | Remainder |
|---|---|---|---|
| 1 | $50 \div 2$ | 25 | 0 |
| 2 | $25 \div 2$ | 12 | 1 |
| 3 | $12 \div 2$ | 6 | 0 |
| 4 | $6 \div 2$ | 3 | 0 |
| 5 | $3 \div 2$ | 1 | 1 |
| 6 | $1 \div 2$ | 0 | 1 |
Read from bottom to top: 110010
So $50_{10} = 110010_2$, which matches the earlier example.
Rule for decimal to binary (division method):
Repeatedly divide by 2, record each remainder, and read the remainders from last to first to get the binary number.
Converting Decimal to Binary: Subtraction (Place Value) Method
Another way uses the place values directly. This method is very useful for 8 bit chunks, which appear constantly in IP addresses.
Algorithm
- List powers of 2 from largest down to 1 that are less than or equal to your number.
- Starting from the largest value, ask: can I subtract this value without going below 0?
- If yes, write 1 for that bit and subtract this value from the current number.
- If no, write 0 for that bit, and do not subtract.
- Move to the next lower power of 2 and repeat until you reach 1.
- The sequence of 1s and 0s is the binary representation.
Example 1: Convert $13_{10}$ with subtraction method
List powers of 2 less than or equal to 13:
128, 64, 32, 16 are too large, the largest that fits is 8, so use:
8, 4, 2, 1
Current number: 13
Check each value:
| Value | Can we subtract? | Bit | New current number |
|---|---|---|---|
| 8 | 13 ≥ 8 yes | 1 | 13 − 8 = 5 |
| 4 | 5 ≥ 4 yes | 1 | 5 − 4 = 1 |
| 2 | 1 ≥ 2 no | 0 | 1 |
| 1 | 1 ≥ 1 yes | 1 | 1 − 1 = 0 |
Bits: 1 1 0 1, so $13_{10} = 1101_2$.
Example 2: Convert $156_{10}$ to 8 bit binary
For an 8 bit value, the powers of 2 are fixed:
| Bit position | Value |
|---|---|
| 7 | 128 |
| 6 | 64 |
| 5 | 32 |
| 4 | 16 |
| 3 | 8 |
| 2 | 4 |
| 1 | 2 |
| 0 | 1 |
Current number: 156
Check each value:
| Value | Can we subtract? | Bit | New current number |
|---|---|---|---|
| 128 | 156 ≥ 128 yes | 1 | 156 − 128 = 28 |
| 64 | 28 ≥ 64 no | 0 | 28 |
| 32 | 28 ≥ 32 no | 0 | 28 |
| 16 | 28 ≥ 16 yes | 1 | 28 − 16 = 12 |
| 8 | 12 ≥ 8 yes | 1 | 12 − 8 = 4 |
| 4 | 4 ≥ 4 yes | 1 | 4 − 4 = 0 |
| 2 | 0 ≥ 2 no | 0 | 0 |
| 1 | 0 ≥ 1 no | 0 | 0 |
Bits: 1 0 0 1 1 1 0 0
So $156_{10} = 10011100_2$.
This subtraction method is the same idea as how you convert binary to decimal, but in reverse.
Tip: For 8 bit values in networking, always think in the fixed set of place values:
128, 64, 32, 16, 8, 4, 2, 1.
Leading Zeros and Fixed Bit Lengths
In pure mathematics, binary numbers do not need leading zeros. For example, 101 and 00000101 represent the same value.
In networking, it is often necessary to use a fixed number of bits, usually 8, 16, 32, or 128. For example, a typical IP address is written in four decimal numbers, but each of those is actually 8 bits internally.
If your conversion gives fewer bits than required, you add leading zeros on the left.
Example: Write 13 as an 8 bit binary value
From earlier, $13_{10} = 1101_2$.
As an 8 bit value, add zeros to the left:
1101 → 00001101
So the 8 bit representation is 00001101.
Example: Write 5 as an 8 bit binary value
$5_{10} = 101_2$.
As 8 bits, write 00000101.
Rule:
Leading zeros on the left do not change the numeric value of a binary number, but are important when a fixed number of bits is required.
Common 8 Bit Values in Networking
For networking tasks, certain decimal values and their 8 bit binary forms appear very often. Learning these helps a lot later.
| Decimal | Binary (8 bit) |
|---|---|
| 0 | 00000000 |
| 1 | 00000001 |
| 2 | 00000010 |
| 4 | 00000100 |
| 8 | 00001000 |
| 16 | 00010000 |
| 32 | 00100000 |
| 64 | 01000000 |
| 128 | 10000000 |
| 255 | 11111111 |
255 is especially important because in 8 bits it is the largest value: all bits set to 1.
You will see 0, 255, and many values between them very often when working with IP addresses and subnet masks.
Checking Your Conversions
It is easy to make small mistakes when converting. One of the best habits is to check your work in the opposite direction.
- If you converted decimal to binary, immediately convert the binary back to decimal using place values.
- See if you get the original decimal number.
- If not, find where a bit was set incorrectly.
Example: Check $156_{10} = 10011100_2$
Take 10011100 and apply place values:
| Bit | Value | Contribution |
|---|---|---|
| 1 | 128 | 128 |
| 0 | 64 | 0 |
| 0 | 32 | 0 |
| 1 | 16 | 16 |
| 1 | 8 | 8 |
| 1 | 4 | 4 |
| 0 | 2 | 0 |
| 0 | 1 | 0 |
Add: $128 + 16 + 8 + 4 = 156$, so the conversion is correct.
Good practice:
Whenever possible, verify conversions by converting back in the other direction. This catches many small errors early.
Summary
Decimal and binary are two ways to write the same numeric values. Networking devices use binary internally, while humans usually see decimal. Converting between these forms relies on the concept of place values and powers of 2.
To convert binary to decimal, expand each bit by its power of 2 and add the values where the bit is 1. To convert decimal to binary, you can use repeated division by 2 with remainders, or the subtraction method using powers of 2.
In networking contexts you will often work with fixed bit lengths, especially 8 bits. Leading zeros are used to fill out these fixed sizes. The skills learned here will be used repeatedly in later chapters, especially when you work with IP addressing and subnetting.
Views: 0
Where to Move
Move chapter:
- ☰ 1. Introduction to Networking
- ☰ 1.1. What is a Computer Network?
- ☰ 1.2. Why Networks Matter
- ☰ 1.3. Types of Networks
- ☰ 1.3.1. PAN
- ☰ 1.3.2. LAN
- ☰ 1.3.3. MAN
- ☰ 1.3.4. WAN
-
- ☰ 1.4. Network Topologies
- ☰ 1.4.1. Bus
- ☰ 1.4.2. Star
- ☰ 1.4.3. Ring
- ☰ 1.4.4. Mesh
-
- ☰ 1.5. Network Components
- ☰ 1.5.1. Hosts
- ☰ 1.5.2. Clients / Servers
- ☰ 1.5.3. NICs
- ☰ 1.5.4. Switches
- ☰ 1.5.5. Routers
- ☰ 1.5.6. Modems
-
- ☰ 1.6. Bandwidth, Latency, Throughput
-
- ☰ 2. Binary and Networking Fundamentals
- ☰ 2.1. Binary Numbers
- ☰ 2.2. Bits vs Bytes
- ☰ 2.3. Decimal ↔ Binary Conversion
- ☰ 2.4. Hexadecimal Basics
- ☰ 2.5. Data Units (Kbps, Mbps, Gbps)
- ☰ 2.6. Encapsulation
-
- ☰ 3. OSI Model
- ☰ 3.1. Why Layering?
- ☰ 3.2. Overview of 7 Layers
- ☰ 3.3. Physical Layer
- ☰ 3.4. Data Link Layer
- ☰ 3.5. Network Layer
- ☰ 3.6. Transport Layer
- ☰ 3.7. Session Layer
- ☰ 3.8. Presentation Layer
- ☰ 3.9. Application Layer
- ☰ 3.10. Encapsulation & Decapsulation
- ☰ 3.11. Packet Journey
-
- ☰ 4. TCP/IP Model
- ☰ 4.1. TCP/IP vs OSI
- ☰ 4.2. Internet Layer
- ☰ 4.3. Transport Layer
- ☰ 4.3.1. Ports & Sockets
- ☰ 4.3.2. TCP Overview
- ☰ 4.3.3. Three-Way Handshake
- ☰ 4.3.4. Reliable Transmission
- ☰ 4.3.5. Flow Control
- ☰ 4.3.6. Congestion Control
- ☰ 4.3.7. UDP
- ☰ 4.3.8. TCP vs UDP
-
- ☰ 4.4. Application Layer
- ☰ 4.5. Packet Flow
-
- ☰ 5. Physical Layer & Transmission Media
- ☰ 5.1. Electrical Signals
- ☰ 5.2. Copper Cables
- ☰ 5.2.1. Twisted Pair
- ☰ 5.2.2. Coaxial
-
- ☰ 5.3. Fiber Optics
- ☰ 5.4. Wireless Transmission
- ☰ 5.5. Duplex Modes
- ☰ 5.6. Signal Loss
- ☰ 5.7. Error Detection
-
- ☰ 6. Ethernet and Switching
- ☰ 6.1. Ethernet Basics
- ☰ 6.2. MAC Addresses
- ☰ 6.3. Ethernet Frames
- ☰ 6.4. Collision Domains
- ☰ 6.5. Broadcast Domains
- ☰ 6.6. Hubs vs Switches
- ☰ 6.7. MAC Learning
- ☰ 6.8. VLANs
- ☰ 6.9. Trunking (802.1Q)
- ☰ 6.10. Spanning Tree Protocol
-
- ☰ 7. IP Addressing
- ☰ 7.1. IPv4 Fundamentals
- ☰ 7.2. Public vs Private IP
- ☰ 7.3. Classful Addressing
- ☰ 7.4. Subnet Masks
- ☰ 7.5. CIDR
- ☰ 7.6. Subnetting
- ☰ 7.7. VLSM
- ☰ 7.8. Supernetting
- ☰ 7.9. IP Planning
-
- ☰ 8. IPv6
- ☰ 8.1. Why IPv6?
- ☰ 8.2. IPv6 Address Format
- ☰ 8.3. Address Types
- ☰ 8.4. IPv6 Header
- ☰ 8.5. SLAAC
- ☰ 8.6. Neighbor Discovery
- ☰ 8.7. IPv4 vs IPv6
-
- ☰ 9. Routing Fundamentals
- ☰ 9.1. What is Routing?
- ☰ 9.2. Static Routing
- ☰ 9.3. Dynamic Routing
- ☰ 9.4. Routing Tables
- ☰ 9.5. Administrative Distance
- ☰ 9.6. Metrics
- ☰ 9.7. Default Routes
- ☰ 9.8. Route Summarization
-
- ☰ 10. Routing Protocols
- ☰ 10.1. Distance Vector Routing
- ☰ 10.2. Link State Routing
- ☰ 10.3. RIP
- ☰ 10.4. OSPF
- ☰ 10.5. EIGRP
- ☰ 10.6. BGP
- ☰ 10.7. Path Selection
- ☰ 10.8. Convergence
-
- ☰ 11. ARP, ICMP, and Core Protocols
- ☰ 11.1. ARP
- ☰ 11.2. Gratuitous ARP
- ☰ 11.3. ICMP
- ☰ 11.4. Ping
- ☰ 11.5. Traceroute
- ☰ 11.6. MTU & Fragmentation
-
- ☰ 12. DNS and Name Resolution
- ☰ 12.1. Why DNS?
- ☰ 12.2. Domain Hierarchy
- ☰ 12.3. Recursive Queries
- ☰ 12.4. DNS Record Types
- ☰ 12.4.1. A
- ☰ 12.4.2. AAAA
- ☰ 12.4.3. CNAME
- ☰ 12.4.4. MX
- ☰ 12.4.5. TXT
-
- ☰ 12.5. DNS Caching
- ☰ 12.6. DNS Security
-
- ☰ 13. Application Layer Protocols
- ☰ 13.1. HTTP / HTTPS
- ☰ 13.2. FTP / SFTP
- ☰ 13.3. SMTP
- ☰ 13.4. POP3
- ☰ 13.5. IMAP
- ☰ 13.6. SSH
- ☰ 13.7. Telnet
- ☰ 13.8. DHCP
- ☰ 13.9. SNMP
- ☰ 13.10. NTP
-
- ☰ 14. Wireless Networking
- ☰ 14.1. Radio Fundamentals
- ☰ 14.2. Wi-Fi Standards
- ☰ 14.3. Frequency Bands
- ☰ 14.4. Channels
- ☰ 14.5. Roaming
- ☰ 14.6. Interference
- ☰ 14.7. WPA2 / WPA3
- ☰ 14.8. Enterprise Wi-Fi
-
- ☰ 15. NAT and Internet Connectivity
- ☰ 15.1. NAT Basics
- ☰ 15.2. PAT
- ☰ 15.3. Port Forwarding
- ☰ 15.4. ISP Concepts
- ☰ 15.5. CGNAT
- ☰ 15.6. Internet Routing
-
- ☰ 16. Network Security Fundamentals
- ☰ 16.1. CIA Triad
- ☰ 16.2. Firewalls
- ☰ 16.3. ACLs
- ☰ 16.4. VPN
- ☰ 16.5. IDS / IPS
- ☰ 16.6. Zero Trust
- ☰ 16.7. DDoS
- ☰ 16.8. Malware in Networks
- ☰ 16.9. Security Hardening
-
- ☰ 17. Network Services
- ☰ 17.1. Load Balancing
- ☰ 17.2. Reverse Proxy
- ☰ 17.3. Web Hosting
- ☰ 17.4. CDN
- ☰ 17.5. DNS Hosting
-
- ☰ 18. Monitoring and Troubleshooting
- ☰ 18.1. Troubleshooting Methodology
- ☰ 18.2. Layer-by-Layer Debugging
- ☰ 18.3. Ping / Traceroute
- ☰ 18.4. Netstat
- ☰ 18.5. Tcpdump
- ☰ 18.6. Wireshark
- ☰ 18.7. Logs
- ☰ 18.8. Packet Analysis
-
- ☰ 19. Virtualization and Cloud Networking
- ☰ 19.1. Virtual Switches
- ☰ 19.2. Hypervisors
- ☰ 19.3. SDN
- ☰ 19.4. Overlay Networks
- ☰ 19.5. Containers & Networking
- ☰ 19.6. Kubernetes Networking
- ☰ 19.7. Cloud VPCs
-
- ☰ 20. Advanced Enterprise Networking
- ☰ 20.1. MPLS
- ☰ 20.2. VXLAN
- ☰ 20.3. EVPN
- ☰ 20.4. SD-WAN
- ☰ 20.5. QoS
- ☰ 20.6. Traffic Engineering
-
- ☰ 21. Automation & Infrastructure as Code
- ☰ 21.1. Why Automation?
- ☰ 21.2. APIs
- ☰ 21.3. REST
- ☰ 21.4. Python for Networking
- ☰ 21.5. Netmiko
- ☰ 21.6. Ansible
- ☰ 21.7. Terraform
- ☰ 21.8. Configuration Management
-
- ☰ 22. Network Design
- ☰ 22.1. Small Office Design
- ☰ 22.2. Enterprise Design
- ☰ 22.3. Data Center Networks
- ☰ 22.4. Redundancy
- ☰ 22.5. High Availability
- ☰ 22.6. Capacity Planning
-
- ☰ 23. Specialized Topics
- ☰ 23.1. IoT Networking
- ☰ 23.2. Industrial Networks
- ☰ 23.3. 5G Basics
- ☰ 23.4. Satellite Networks
- ☰ 23.5. HPC Networking (InfiniBand, RDMA)
- ☰ 23.6. Edge Computing
-
- ☰ 24. Capstone Projects
- ☰ 24.1. Home Lab Project
- ☰ 24.2. Enterprise Network Design
- ☰ 24.3. Secure Multi-Site Network
- ☰ 24.4. Packet Analysis Project
- ☰ 24.5. Cloud Networking Project
-
- ☰ 25. Bonus Content
- ☰ 25.1. Certification Prep (CCNA / CCNP)
- ☰ 25.2. Interview Questions
- ☰ 25.3. Hands-on Labs
- ☰ 25.4. Real-World Case Studies
- ☰ 25.5. Final Exam
-
Comments
Please login to add a comment.
Don't have an account? Register now!