# 1. Binary and Hexadecimal Systems

# Overview of this chapter

- Binary System
- Basic unit
- Conversion between Binary and Denary

- Hexadecimal System
- Advantage & Usage
- Conversion between Hex and Denary

- Conversion between Binary and Hex

## 1.1 Binary System

The binary number system (base 2) which comprises of only 0s and 1s is used by computers to process all data.

**UNIT**

- Bit: a binary digit

E.g. 0 or 1 is represented by 1 bit - Nibble = 4 bits
- Byte = 8 bits

1 character = 1 byte - 1 KB = 2^10 B = 1024 bytes
- 1 MB = 2^20 B = 1024 KB
- 1 GB = 2^30 B = 1024 MB
- 1 TB = 2^40 B = 1024 GB

**Note**: In the exam, because of lack of calculator, examiners usually permits using 1000 in the conversion between units.

**CONVERSION**

*From Denary to Binary*

Process: **Divide the denary number by two repeatedly**, meanwhile keep track of **remainders** after each division, until the quotient is 0. Assemble the set of remainders **reversely**

Example: Convert 25(base 10) from denary to binary:

- Divide by 2

the first remainder is 0 - Divide by 2

the second remainder is 1

… - Divide by 2

the fifth remainder is 1

the quotient is 0 - Assemble all remainders in opposite direction, we get 11001(base2)

*From Binary to Denary*

- Multiply each bit by 2n, where n is the position of the bit, start from 0 on the right
- Add up the results
- Example: Convert 11001 to denary

1 * 2^4 + 1* 2^3 + 0* 2^2 + 0 * 2^1 + 1 * 2^0 = 16 + 8 + 1 = 25

## 1.2 Hexadecimal System

**ADVANTAGE**

- Easier for humans to communicate with computersCOMPARE TO THE BINARY SYSTEM, 4 BITS IS REPRESENTED BY A SINGLE SYMBOL
- Fewer digits to use
- Smaller Screen is required
- Easier to find errors / less likely to make errors
- Faster than entering binary digits
- Conversion to binary is easier than denary to binary

**USAGE**

**Display error code**

E.g. #404 – page not found**HTML colour code**

E.g. FF0000 is red**Media Access Control (MAC) addresses**PHYSICAL UNIQUE ADDRESS OF EACH NETWORK INTERFACE CARD THAT MADE UP OF 2 PARTS, MANUFACTURE ID AND SERIAL NUMBERE.g. A4-50-B4-C2-60-3E**Web address**

E.g. www: %77%77%77 (%means hexadecimal is used)- Address of memory location

E.g. STO FFA4

**CONVERSION**

*From Denary to Hexadecimal*

- Divide the number by 16
- Keep track of the remainder
- E.g. Convert 504 to Hexadecimal

16 | 504

16 | 31 | 8

16 | 01 | 15

—- | 00 | 1

Result: 1F8

*From Hexadecimal to Denary*

- Multiply each bit by 16^n, where n is the position of the bit, start from 0 on the right
- Add up the results
- E.g. Convert A to denary

10 * 16^0 = 10

## 1.3 Conversion between Hexadecimal and Binary

**FROM HEX TO BINARY**

- Convert each digit to denary
- Convert each denary digit to 4-bits binary digits
- Merge the digit
- Example: 18F -> 0001 1000 1111 -> 110001111

**FROM BINARY TO HEX**

- Group bits by 4 from right to left
- Add additional zeros to the left if necessary
- Convert each group to denary
- Represents them in hexadecimal
- Example: 110001111 -> 0001 1000 1111 -> 1 8 15 -> 18F