Chapter 1 - Data representation


Number systems

The binary system

  • Base 2 number system

  • Two values 0 and 1 to represent all values

  • Uses power of 2


2^7

2^6

2^5

2^4

2^3

2^2

2^1

2^0

128

64

32

16

8

4

2

1

1

1

1

0

1

1

1

0


Converting from binary to denary

  • Each time a 1-value appears in a binary number column, the column value (heading) is added to a total


128

64

32

16

8

4

2

1

1

1

1

0

1

1

1

0


The equivalent denary number is 128 + 64 + 32 + 8 + 4 + 2 = 238


Converting from denary to binary

  • Successive division by 2 until the value “0” is reached.


2

142

Read the remainders from bottom to top to get the binary number : 

1    0    0    0    1    1    1    0

2

71

remainder:

0

2

35

remainder:

1

2

17

remainder:

1

2

8

remainder:

1

2

4

remainder:

0

2

2

remainder:

0

2

1

remainder:

0

remainder:

1



The hexadecimal system

  • Base 16 number system

  • Uses 16 different digits to represent each value

  • 1 = 1

  • 2 = 2

  • 3 = 3

  • 4 = 4

  • 5 = 5

  • 6 = 6

  • 7 = 7

  • 8 = 8

  • 9 = 9

  • 10 = A

  • 11 = B

  • 12 = C

  • 13 = D

  • 14 = E

  • 15 = F


16^4

16^3

16^2

16^1

16^0

65536

4096

256

16

1

2

1

F

3

A


  • A typical example of hex is 2 1 F 2 A

  • Since 16 = 2^4 this means FOUR binary digits are equivalent to each hexadecimal digit.


















Binary value

Hexadecimal value

Denary value

0000

0

0

0001

1

1

0010

2

2

0011

3

3

0100

4

4

0101

5

5

0110

6

6

0111

7

7

1000

8

8

1001

9

9

1010

A

10

1011

B

11

1100

C

12

1101

D

13

1110

E

14

1111

F

15



Converting from binary to hexadecimal and from hexadecimal to binary

  • Starting from the right, split the denary number into groups of 4 

  • If the last group has less than 4 bits, then simply fill in with 0s from the left

  • Take each group of 4 bits and convert it into the equivalent hexadecimal digit

1 0 1 1 1 1 1 0 0 0 0 1


First split this up into groups of 4 bits: 

1 0 1 1 1 1 1 0 0 0 0 1


Then find the equivalent hexadecimal digits: 

    B     E      1

1 0 1 1 1 1 1 1 0 0 0 0 1 = B E 1


Converting from hexadecimal to denary and from denary to hexadecimal


Convert hexadecimal numbers into denary

  • Take each of the hexadecimal digits and multiple it by the heading values

  • Add all the resultant totals together to give the denary number

  • The hex digits A —> F need to be converted to 10 —> 15 before carrying out the multiplication.


256

16

1

4

5

A

(4 x 256 = 1024)

(5 x 16 = 80)

(10 x 1 = 10)







1024 + 80 + 10 = 1114


Convert from denary to hexadecimal

  • Successive division by 16 until the value “0” is reached.


16

2004

Write the remainders from bottom to top to get the hexadecimal number:

7   D   4    (D = 13)

16

125

remainder:

4

16

7

remainder:

13

0

remainder:

7




Use of the hexadecimal system

  • Error codes

  • MAC addresses

  • IPv6 addresses

  • HTML colour codes


Error codes

  • Memory location of the error and are usually automatically generated by the computer.


Media Access Control (MAC) addresses

  • A number which uniquely identifies a device on a network

  • Refers to the network interface card (NIC)

  • Usually made up of 48 bits which are shown as 6 groups of two hexadecimal digits.

NN - NN - NN - DD - DD - DD

Or

NN:NN:NN:DD:DD:DD

  • (NN - NN - NN) is the identity number of the manufacturer of the device and the (DD - DD - DD) is the serial number of the device


Internet Protocol (IP) addresses

  • Each device connected to a network is given an address known as the Internet Protocol (IP) address.

  • IPv4 is a 32-bit number written in denary or hexadecimal form

  • IPv6 is a 128-bit number broken down into 16-bit chunks represented by a hexadecimal number.

  • IPv6 uses a colon (:) and IPv4 uses a decimal point (.)


HyperText Mark-up Language (HTML) colour codes

  • Used to represent colours of text on the computer screen

  • All colours are made up of different combinations of three primary colours (red, green, blue)

  • Intensity of each colour is determined by its hexadecimal value

# 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




Addition of binary numbers

  • Addition of two binary digits


Binary addition

carry

sum

0 + 0

0

0

0 + 1 

1

1 + 0 

0

1

1 + 1

1

0













  • Addition of three binary digits


Binary digit

carry

sum

0 + 0 + 0

0

0

0 + 0 + 1

0

1

0 + 1 + 0

0

1

0 + 1 + 1 

1

0

1 + 0 + 0

0

1

1 + 0 + 1

1

0

1 + 1 + 0

1

0

1 + 1 + 1

1

1


Ex.

Answer : 0 1 1 1 0 0 0 1



Overflow

  • An overflow error is when the data type used to store data was not large enough to hold the data.





Logic binary shifts

  • Moving the binary number to the left or to the right

  • Each shift left is equivalent to multiplying the binary number by 2 

  • Each shift right is equivalent to dividing the binary number by 2

  • As bits are shifted, any empty positions are replaced with a zero



  • The denary number 21 is 00010101 in binary. If we put this into an 8-bit register:


128

64

32

16

8

4

2

1

0

0

0

1

0

1

0

1






  • If we now shift the bits in this register one place to the left, we obtain:


128

64

32

16

8

4

2

1

0

0

1

0

1

0

1

0






  • The value of the binary bits is now 21 x 2^1 = 42. We can see this is correct if we calculate the denary value of the new binary number 101010 (32 + 8 + 2 = 42)



  • The denary number 200 is 11001000 in binary. If we put this into an 8-bit register:


128

64

32

16

8

4

2

1

1

1

0

0

1

0

0

0






  • If we shift the bits in this register two places to the right, we obtain:


128

64

32

16

8

4

2

1

0

0

1

1

0

0

1

0






  • The value of the binary bits is now 200 / 2^2 = 50. We can see this is correct if we calculated the denary value of the new binary number 00110010 (32 + 16 + 2 = 50).


Two’s complement (binary numbers)

  • Allow the possibility of representing negative integers we make use of two’s complement.

  • In two’s complement, the leftmost bit is changed to a negative value. 

  • 128 is changed to -128 but all the other headings remain the same

  • Range of new possible numbers from -128 (10000000) to +127 (01111111)

  • Leftmost bit always the sign of the binary number

  • 1-value in the leftmost bit indicates a negative number and a 0-value in the leftmost bit indicates a positive number

  • Written in this format:


-128

64

32

16

8

4

2

1


Writing positive binary numbers in two’s complement format

  • Ex. 19 and 4 written in two’s complement:


-128

64

32

16

8

4

2

1

0

0

0

1

0

0

1

1

0

0

0

0

0

1

0

0


Converting positive denary numbers to binary numbers in the two’s complement format

  • Ex. 38

  • Since the number is already a positive number, we put a zero in the -128 value and put the rest of the values as you would normally.


-128

64

32

16

8

4

2

1

0

0

1

0

0

1

1

0


Converting positive binary numbers in the two’s complement format to positive denary numbers

  • Ex. convert 01101110 in two’s complement binary into denary:


-128

64

32

16

8

4

2

1

0

1

1

0

1

1

1

0


  • Each time a 1 appears in a column, the column value is added to the total

  • Ex. 64 + 32 + 8 + 4 + 2 = 110


Writing negative binary numbers in two’s complement format and converting to denary

  • Ex. -109


-128

64

32

16

8

4

2

1

1

0

0

1

0

0

1

1


  • By following our normal rules, each time a 1 appears in a column, the column value is added to the total. So, we can see that in denary this is: -128 + 16 + 2 + 1 = -109








Converting negative denary numbers into binary numbers in two’s complement format

  • Consider the number +67 in 8-bit (two’s complement) binary format:


-128

64

32

16

8

4

2

1

0

1

0

0

0

0

1

1


  • Method 1

Now let’s consider the number -67. One method of finding the binary equivalent to -67 is to simply put 1s in their correct places:


-128

64

32

16

8

4

2

1

1

0

1

1

1

1

0

1


  • Method 2

However, looking at the two binary numbers above, there is another possible way to find the binary representation of a negative denary number:


  • First write the number as a positive binary value - in this case 67:     01000011

  • We then invert each binary value, which means swap the 1s and 0s around:   10111100

  • Then add 1 to that number:         1

  • This gives us the binary for -67:




Text, sound and images

Character sets - ASCII code and Unicode

  • The ASCII code system (American Standard Code for Information Interchange) is used for communication systems and computer systems.

  • The standard ASCII code character set consists of 7-bit codes (0 to 127 in denary or 00 to 7F in hexadecimal) that represents the letters, numbers and characters found on a standard keyboard, together with 32 control codes (that use codes 0 to 31 (denary) or 00 to 19 (hexadecimal)).

  • Unicode can represent all languages of the world, thus supporting many operating systems, search engines and internet browsers used globally. 




Representation of sound

  • Sampling means measuring the amplitude of the sound wave

  • The number of bits per sample is known as the sampling resolution (also known as the bit depth). 

  • Sampling rate is the number of sound samples taken per second. This is measured in hertz (Hz), where 1 Hz means ‘one sample per second’.


Representation of (bitmap) images

  • Bitmap images are made up of pixels (picture elements); an image is made up of a two-dimensional matrix of pixels

  • The number of bits used to represent each colour is called the colour depth

  • Image resolution refers to the number of pixels that make up an image




Data storage and file compression

Calculation of file size

  • The file size of an image is calculated as:

Image resolution (in pixelsO x colour depth (in bits)


  • The size of a mono sound file is calculated as:

Sample rate (in Hz) x sample resolution (in bits) x length of sample (in seconds)


  • For a stereo sound file, you would then multiply the result by two.


Lossy and lossless file compression

Lossy file compression

  • The file compression algorithm eliminates unnecessary data from the file. This means the original file cannot be reconstructed once it has been compressed.


Lossless file compression

  • All the data from the original uncompressed file can be reconstructed. This is particularly important for files where any loss of data would be disastrous.

  • Run-length encoding (RLE) can be used for lossless compression of a number of different file formats