KAHIBARO Bookshelves
Discord Login Register

2.4. Hexadecimal Basics

Understanding Hexadecimal

Hexadecimal, often shortened to “hex,” is a way to write numbers using base 16 instead of base 10. In everyday life you use base 10, which has ten digits from 0 to 9. Hexadecimal has sixteen digits. This makes hex very useful in computing, especially when you work with binary, because it gives a compact and readable way to represent long binary patterns.

In this chapter you will see what the hex digits are, how to read and write hex numbers, and why hex is convenient when dealing with networking and low level data. You will connect it later to binary conversions and data representation, so the goal here is to understand the system itself and how to use it in simple conversions.

Hexadecimal Digits

Hexadecimal needs sixteen symbols. The first ten are the same as decimal. For the extra six values, the letters A to F are used.

Hex digitDecimal value
00
11
22
33
44
55
66
77
88
99
A10
B11
C12
D13
E14
F15

A single hexadecimal digit can therefore represent any value from 0 to 15. When you see A in hex, you should think “ten.” When you see F, you should think “fifteen.”

Place Values in Hex

Hexadecimal is a positional number system. This means the position of each digit matters, just like in decimal.

In decimal, from right to left, the places are powers of 10:

  • Ones: $10^0 = 1$
  • Tens: $10^1 = 10$
  • Hundreds: $10^2 = 100$ and so on.

In hexadecimal, from right to left, the places are powers of 16:

  • Ones: $16^0 = 1$
  • Sixteens: $16^1 = 16$
  • Two hundred fifty six: $16^2 = 256$
  • Four thousand ninety six: $16^3 = 4096$ and so on.

This pattern leads to a general rule for the value of a hex number.

Rule: Value of a hexadecimal number
For a hex number with digits $d_{n-1} d_{n-2} \dots d_1 d_0$ (each $d$ is 0 to 15), its decimal value is
$$\text{value} = \sum_{i=0}^{n-1} d_i \cdot 16^i$$
The rightmost digit has $i = 0$.

For example, take the hex number 2A. Here:

  • A is the ones place and means 10.
  • 2 is the sixteens place and means $2 \times 16 = 32$.

So the total decimal value is $32 + 10 = 42$.

Writing and Reading Hex Numbers

In many technical texts hexadecimal numbers are marked clearly so that you do not confuse them with decimal. There are several common notations:

Notation styleExampleMeaning
Suffix h2AhHex 2A
Prefix 0x0x2AHex 2A
Prefix 0X0X2AHex 2A

You may also see hex numbers written without any prefix or suffix when the context is clear, for example inside an IPv6 address or a MAC address. In this chapter you can assume that any value that contains letters A to F is hexadecimal.

When you read hex numbers, it helps to translate each digit to its decimal value in your head, then remember which place value it has. For a beginner it is useful to say it aloud. For example, 3F in hex can be read as “three times sixteen plus fifteen.”

Manual Conversion from Hex to Decimal

You will have a separate chapter that covers number conversions in general. Here you will see the specific method for hex to decimal, because it is central to understanding hex itself.

To convert a hexadecimal number to decimal, follow these steps:

  1. Write down the hex number and label the positions, starting from 0 at the right.
  2. Convert each hex digit to its decimal value.
  3. Multiply each value by $16^{\text{position}}$.
  4. Add the results.

For example, convert 0x1C to decimal.

  • C is 12 and is at position 0, so you have $12 \times 16^0 = 12 \times 1 = 12$.
  • 1 is 1 and is at position 1, so you have $1 \times 16^1 = 1 \times 16 = 16$.
  • Add them to get $16 + 12 = 28$.

You can set this up in a small table to keep track:

Hex digitPositionDecimal valuePower of 16Contribution
111$16^1 = 16$$1 \times 16=16$
C012$16^0 = 1$$12 \times 1=12$

Total decimal value is $16 + 12 = 28$.

Here is another example with three digits, 0x2F4.

  • Positions from right to left are 0, 1, 2.
  • 4 is 4 at position 0: $4 \times 16^0 = 4 \times 1 = 4$.
  • F is 15 at position 1: $15 \times 16^1 = 15 \times 16 = 240$.
  • 2 is 2 at position 2: $2 \times 16^2 = 2 \times 256 = 512$.
  • Total is $512 + 240 + 4 = 756$.

Once you know the first few powers of 16, this process becomes much faster.

Powers of 16 to Remember

You do not need to memorize many powers of 16 to work comfortably with hex. The most useful ones fit into a small table.

ExponentPower of 16Decimal value
$16^0$11
$16^1$1616
$16^2$16 × 16256
$16^3$16 × 16 × 164096
$16^4$16⁴65536

With this table, you can quickly work out many common hex values. For example, hex 100 is

  • $1 \times 16^2 = 1 \times 256 = 256$,
    because the two zeros add no extra value.

Ranges Representable with Hex Digits

Because each hex digit can hold 16 values, you can easily compute the range of values that can be stored with a certain number of hex digits.

For one hex digit you have values from 0 to 15.
For two hex digits you have $16^2 = 256$ possible combinations, from 00 to FF.
For three hex digits you have $16^3 = 4096$ combinations, from 000 to FFF.

The maximum value with $n$ hex digits is always one less than $16^n$.

Rule: Maximum value for $n$ hex digits
With $n$ hexadecimal digits, the maximum integer value is
$$\text{max} = 16^n - 1$$
For example, with 2 digits the maximum is $16^2 - 1 = 256 - 1 = 255$, which is FF in hex.

This rule shows up a lot in networking, for example when you look at limits on fields inside protocol headers.

Grouping and Formatting Hex Values

In practice, long hex sequences are split into groups to make them easier to read. You will see several grouping styles in networking:

  • Bytes written as pairs of hex digits, for example 4A, FF, 09.
  • Bytes separated by colons or hyphens, for example 01:23:45:67:89:AB or 01-23-45-67-89-AB.
  • Groups of four hex digits separated by colons, as in many IPv6 addresses.

Each pair of hex digits forms a natural unit, which you will later learn to relate to a byte. For now the key idea is that 2 hex digits are usually read together as one chunk of information.

When you see many hex digits next to each other, try to break them into groups of two from the right. This will help you read and work with them more easily.

Where Hexadecimal Appears in Networking

Hexadecimal is common throughout networking because it makes long binary values shorter and more readable, while still mapping cleanly to the underlying bits. You will see hex in several places later in the course, such as:

  • Addresses that contain letters and numbers, for example specific address formats that do not look like decimal IPv4 addresses.
  • Representations of protocol headers in packet analysis tools.
  • Configuration fields that are given as hex values in device interfaces or logs.

You do not need to understand those networking uses yet. At this stage it is enough to recognize that when you see values with A to F in them, you are most likely looking at hexadecimal, and to be comfortable reading and converting those numbers.

Practicing with Simple Hex Values

To get used to hexadecimal, it is useful to become fluent with small hex numbers, especially the range from 0 to FF. These are the values that appear most often when data and addresses are shown in hex form.

Here are some simple examples that you can practice in both directions in your head:

HexDecimal
00
99
A10
F15
1016
1F31
2032
2A42
3C60
7F127
FF255

If you can look at values like 7F and FF and quickly recall their decimal meanings, later parts of networking, such as reading address fields and packet dumps, will feel much more natural.

In later chapters you will connect hexadecimal directly to binary and learn faster methods for converting between the two. For now, a clear understanding of what hex is, how place values work, and how to perform basic hex to decimal conversion is enough.

Views: 0

Comments

Please login to add a comment.

Don't have an account? Register now!

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