As we have seen, a computer can only work with binary data. Whilst computer scientists can work with binary, they find hexadecimal to be more convenient to use. This is because one hex digit represents four binary digits. A complex binary number, such as 1101001010101111 can be written in hex as D2AF. The hex number is far easier for humans to remember, copy and work with. This section reviews four uses of the hexadecimal system:
» error codes
» MAC addresses
» IPv6 addresses
» HTML colour codes
Error codes are often shown as hexadecimal values. The programmer needs to know how to interpret the hexadecimal error
codes. Examples of error codes from a Windows system are shown below:
Media Access Control (MAC) addresses:
Media Access Control (MAC) address refers to a number which uniquely identifies a device on a network. The MAC address refers to the network interface card (NIC) which is part of the device. The MAC address is rarely changed so that a particular device can always be identified no matter where it is. A MAC address is usually made up of 48 bits which are shown as 6 groups of two hexadecimal digits (although 64-bit addresses also exist):
NN – NN – NN – DD – DD – DD
or
NN:NN:NN:DD:DD:DD
Where the first half (NN – NN – NN) is the identity number of the manufacturer of the device and the second half (DD – DD – DD) is the serial number of the device.
For example:
00 – 1C – B3 – 4F – 25 – FE is the MAC address of a device produced by the Apple
Corporation (code: 001CB3) with a serial number of: 4F25FE. Very often lowercase
hexadecimal letters are used in the MAC address: 00-1c-b3-4f-25-fe.
Internet Protocol (IP) addresses:
Each device connected to a network is given an address known as the Internet
Protocol (IP) address. An IPv4 address is a 32-bit number written in denary or
hexadecimal form: e.g. 109.108.158.1 (or 77.76.9e.01 in hex). IPv4 has recently
been improved upon by the adoption of IPv6. An IPv6 address is a 128-bit
number broken down into 16-bit chunks, represented by a hexadecimal number.
For example:
a8fb:7a88:fff0:0fff:3d21:2085:66fb:f0fa
HyperText Mark-up Language (HTML) colour codes
HyperText Mark-up Language (HTML) is used when writing and developing web pages. HTML isn’t a programming language but is simply a mark-up language. A mark-up language is used in the processing, definition and presentation of text
(for example, specifying the color of the text).
HTML uses <tags> which are used to bracket a piece of text for example, <h1>
and </h1> surround a top-level heading. Whatever is between the two tags has been defined as heading level 1. Here is a short example of HTML code:
<h1 style="color:#FF0000;">This is a red heading</h1>
<h2 style="color:#00FF00;">This is a green heading</h2>
<h3 style="color:#0000FF;">This is a blue heading</h3>
HTML is often used to represent colours of text on the computer screen. All colours can be made up of different combinations of the three primary colours (red, green and blue). The different intensity of each colour (red, green and blue) is determined by its hexadecimal value. This means different hexadecimal values represent different colours. For example:
» # FF 00 00 represents primary colour red
» # 00 FF 00 represents primary colour green
» # 00 00 FF represents primary colour blue
» # FF 00 FF represents fuchsia
» # FF 80 00 represents orange
» # B1 89 04 represents a tan colour,
and so on producing almost any colour the user wants. The following diagrams
show the various colours that can be selected by altering the hex ‘intensity’ of
red, green and blue primary colours. The colour ‘FF9966’ has been chosen as an
example:
The # symbol always precedes hexadecimal values in HTML code. The color codes are always six hexadecimal digits representing the red, green and blue components. There are a possible 256 values for red, 256 values for green and 256 values for blue giving a total of 256 × 256 × 256 (i.e. 16 777 216) possible colors.
Logical binary shifts
Computers can carry out a logical shift on a sequence of binary numbers. The logical shift means moving the binary number to the left or to the right. Each shift left is equivalent to multiplying the binary number by 2 and each shift right is equivalent to dividing the binary number by 2. As bits are shifted, any empty positions are replaced with a zero.
There is clearly a limit to the number of shifts that can be carried out if the binary number is stored in an 8-bit register.
Eventually, after a number of shifts the register would only contain zeros. For example, if we shift 01110000 (denary value 112) five places left (the equivalent to multiplying by 25, i.e. 32), in an 8-bit register we would end up with 00000000. This makes it seem as though 112 × 32 = 0! This would result in the generation of an error message.