GCSE Computer Science/Hexadecimal

In the previous section you learned that Humans tend to use a base-10 number system known as denary (also known as decimal). Computers however work in base-2, or binary. Sometimes an intermediate step is used which is a bit easier for Humans to deal with than binary is and a bit easier for computers to deal with than denary is. This is a 'base-16' number system known as hexadecimal.

Numerals

edit
Specification link

Represent integers as hexadecimal numbers - 2016 CIE Syllabus p10

In hexadecimal we have 16 numerals, shown together with binary and denary in the table below:

Binary Denary Hexadecimal
base-2 base-10 base-16
0 0 0
1 1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
A
B
C
D
E
F

Converting

edit
Specification link

- convert positive hexadecimal integers to and from denary
- convert positive hexadecimal integers to and from binary
- 2016 CIE Syllabus p10

To Hexadecimal

edit
  1. Convert the number into binary.
  2. Split the binary number into groups of 4 bits.
  3. Convert each group of 4 bits back to denary.
  4. Convert each denary number into a single hexadecimal numeral.

From Hexadecimal

edit
  1. Convert each hexadecimal numeral into its denary value.
  2. Convert each denary number into 4-bit binary.
  3. Join the 4-bit numbers together to create a single binary number.
  4. Convert this binary number to denary.

Uses of Hexadecimal

edit
Specification link

- Show understanding of the reasons for choosing hexadecimal to represent numbers
- Represent numbers stored in registers and main memory as hexadecimal
- Identify current uses of hexadecimal numbers in computing
- 2016 CIE Syllabus p10

Hexadecimal is used as an intermediate step between binary and denary because it is easier for a computer to convert between binary and hexadecimal than between binary and denary whilst at the same time being easier for a Human to process than a binary number would be. It is also used because a single hexadecmical numeral can store 1 nibble and we can store a whole byte using only 2 hexadecimal numerals. Depending on the application this can have benefits in both storage space and processing time.

HTML Colour Codes

edit

One example of how hexadecimal is used in computers would be HTML colour codes. In HTML colours are defined by how much red, green and blue there is on a scale of 0 to 255. The range 0 to 255 was chosen because that is the range of numbers that can be fitted into a single byte and a single byte can be represented as two hexadecimal numerals. HTML colour codes start with a hash symbol followed by 3 pairs of hexadecimal numbers. The first two numerals show how much red, the second pair show how much green and the final pair show how much blue. For example the HTML colour code #00FF00 would have 00 (0) units of red, FF (255) units of green and 00 (0) units of blue. The diagram below shows several examples of HTML colour codes. More can be found on the website html-color-codes.info.

#0000FF #00FF00 #FF0000 #FF00FF #FFFF00 #000000 #FFFFFF

HTML colour codes are given in hexadecimal values rather than decimal values as this uses fewer characters which therefore makes the file smaller, which in turn would allow the page to load faster over a slow network connection.

MAC Addresses

edit

All network adapters and network devices have a Media Access Control (MAC) address. This is also known as the 'physical address' and is a unique address determined during the manufacture of each device. This address is given as a set of 6 pairs of hexadecimal numbers. An example of a MAC address would beĀ : A0-1D-48-FE-5E-F5. You can determine the physical address of the network adapters in a computer running the Windows operating system by typing the following command into a command prompt:

ipconfig /all

Other Uses

edit

Hexadecimal is used extensively in assembly programming languages and in machine code. It is often used to refer to memory addresses. It can be used during the debugging stage of writing a computer program and to represent numbers stored in a CPU's registers or in main memory.