Tech Stuff - Hexadecimal, Decimal and Binary

The basic unit used in the computer world is the byte (a.k.a octet), a byte (or octet) has 8 bits (a.k.a binary digits). Most modern systems use multiples of a byte, thus, a 16-bit system is comprised of 2 bytes (2 x 8 = 16), a 32-bit system has 4 bytes (4 x 8 = 32) and a 64-bit system has 8 bytes (8 x 8 = 64). The term word, as in the description 32-bit word has largely disappeared from the technical lexicon.

The contents of any byte, for instance, in a memory location or on a network, can be expressed in many numbering systems. The most commonly used numbering systems are Decimal, Hexadecimal and Binary:

Numbering System

Base

Range

Notes

Decimal

base 10

0 - 1,2,3...

The most common numbering system - dollars, metric etc. A byte (8 bits) has 256 possible values in the range 0 - 255

Binary

base 2

0 - 1

The basic level at which the electronic circuitry in a computer works - a single bit.

Hexadecimal

base 16

0-9, A-F

Each Hexadecimal character represents 4 bits (0 - 15 decimal) which is called a nibble (a small byte - honest!). A byte (or octet) is 8 bits so is always represented by 2 Hex characters in the range 00 to FF.

Historical Note: Once upon a time, when the world, and even the author of this page, was young, computers were built with 12-bit, 24-bit and even 36-bit words (it made some sense then, just looks strange today). Each of these word sizes is divisible by 3 and used an octal (base 8) numbering system. Each 3 bit element contained 8 values in the range 0 to 7. Thus, a memory location with the 12-bit binary value of 000.001.100.111 would be written in octal as 0147.

Bit numbering

When working with binary each bit within a byte (octet) may need to be identified using a technique called bit numbering. Bit numbering can be very confusing with various standard bodies adopting different conventions. The following are all valid, and used, bit numbering conventions for describing an 8 bit byte (an octet).

Memory contents

0

0

0

0

0

0

0

0

Bit numbering conventions

Left to right base 0 (IETF)

0

1

2

3

4

5

6

7

Left to right base 1

1

2

3

4

5

6

7

8

Right to left base 1 (ITU)

8

7

6

5

4

3

2

1

Power of 2

7

6

5

4

3

2

1

0

Always check what convention is used on any specification. We have bowed to the inevitable and use the Left to right base 0 (IETF) standard since, because of the Internet, it is widely used and, hopefully, equally widely understood. The IETF's rationale for this standard is that it also represents unambiguously what is called network order, that is, bit 0 goes onto a network first, bit 1 second and so on. Bits also tend to come off the network in the same order they went on. Use of network order is necessary since the internal (machine) representation of data can vary enormously (all that big-endian, little-endian nonsense) but when data is stuffed onto a network it must be in a consistent order that can be used by any system, irrespective of its internal representation, that wants to use the data.

Finally, when working with binary you will frequently come accross the terms Most Significant Bit(s) (MSB) and Least Significant Bit(s) (LSB). The MSB is always on the LEFT and the LSB on the RIGHT. Thus, using IETF bit numbering the MSB is bit 0 and the LSB is bit 7, whereas using ITU bit numbering the MSB is bit 8 and the LSB is bit 1. Crystal clear, right?

IPv4 Decimal to Hex Conversion

To convert a dotted decimal IPv4 address to hexadecimal, take each dotted decimal value and convert it using a hex calculator (standard windows calculator in scientific or prgrammer mode will do the job). This will yield:

Problems, comments, suggestions, corrections (including broken links) or something to add? Please take the time from a busy life to 'mail us' (at top of screen), the webmaster (below) or info-support at zytrax. You will have a warm inner glow for the rest of the day.