Slides badge

Data Representation

Learning Intentions

  • Understand Two’s complement, how to calculate range of numbers representable in binary

  • Understand how to use floating point representation with binary

  • Understand what Unicode is and the pros and cons of it

  • Understand the difference between binary and vector graphics

Success Criteria

  • Be able to convert binary and denary using Two's complement
  • Be able to convert floating point numbers to binary and vice versa
  • Be able to explain what Unicode is and it's pros and cons compared with ASCII
  • Be able to discuss the differences between bitmap and vector graphics

Binary from N5

  • The binary system is the way in which a computer represents positive and negative whole numbers.

  • Binary is a two state system which means numbers are represented using a series of 1s and 0s

  • 1 meaning a voltage is present and a 0 meaning a voltage is not present - specifically transistors turn on at around 0.7 volts

  • At National 5 level, we only had to deal with positive numbers, but at higher we need to know how to convert positive and negative numbers

Figuring out denary from a binary number

  • Let’s figure out what the binary number 1001 means in denary:

 

   

 

 

  • To do this, add each number with a 1 under it together, so 8 + 1. Total is 9. So 1001 = 9.

23 22 21 20
8 4 2 1
1 0 0 1

Example 1

  • Convert:

    1000 1000

    To denary.

Example 2

  • Convert:

    1100 1111

    To denary.

Example 3

  • Convert:

    0010 0100

    To denary.

Figuring out binary from a denary number

  • Reversing binary to give us a decimal number is a bit trickier. The placeholders are the same and should be put at the top. Hint: the leftmost placeholder should be no bigger than the denary number.

  • Let’s calculate the number 17:

     

16 8 4 2 1
1 0 0 0 1

Denary to binary

  • Now let’s calculate 35:




  • Double check it by adding all the numbers with a 1 under them together.​32 + 2 + 1 = 35

32 16 8 4 2 1
1 0 0 0 1 1

Example 1

  • Convert:

    28

    To 8-bit binary

Example 2

  • Convert:

    32

    To 8-bit binary

Example 3

  • Convert:

    254

    To 8-bit binary

aDVANTAGES OF BINARY

  • Fewer arithmetic operations

  • Any slight voltage drop does not change the data.
        Imagine trying to represent 0 to 9 with discrete voltages!
        Just use zero volts = 0,   any volts = 1

  • Two state storage is easy in storage devices such as CDs

DISADVANTAGES OF BINARY

  • Large number of digits required for even moderately large numbers 

    E.g. 1000 0000 0000     =     4096
           (12 digits)                       (4 digits)

rEPRESENTING NEGATIVE NUMBERS

  • Previously, we’ve only had to deal with positive numbers, but how does a computer represent negative whole numbers?

  • We use Two’s complement (note the spelling of complement).

  • Two’s compliment allows us to represent both positive and negative numbers and there’s two methods to do it.

Method 1

  • This method is carried out using three steps. 

    1. Find the positive value
    2. Switch the 1s and 0s
    3. Add 1
  • Let’s convert -116 using 8-bit Two’s complement
     

Method 1

  • Step 1– Find positive 116 in Binary

128 64 32 16 8 4 2 1
0 1 1 1 0 1 0 0

64 + 32 + 16 + 4 = 116

Method 1

  • Step 2 - Switch all the 1s and 0s:

    • Our next step is to switch the 1s and 0s around.

    • In a Two’s complement number if the left most bit is 1 then its  a negative number, if it’s a 0 then it’s a positive number. 

-128 64 32 16 8 4 2 1
1 0 0 0 1 0 1 1

Notice that the 128 has become -128. This helps with the next bit

Method 1

  • Step 3 - Add 1

    • We need to move to the right hand side and add a 1 where we see our first 0 and then replace the 1s with a 0

-128 64 32 16 8 4 2 1
1 0 0 0 1 0 1 1

This becomes 1

These become 0

-128 64 32 16 8 4 2 1
1 0 0 0 1 1 0 0

The other way...

  • That method isn't the only method, there are actually several. 

  • The first method has a lot of steps involved in it.

  • The second method is easier and can also be used as a verification technique if you do choose to use the first method.

Method 2

  • Step 1 - Start negative

    • Start with your column headings. Make sure you’re left most bit (128) is negative!

 

 

  • Step 2 - Put a 1 under the first column
    • Put a 1 under 128
-128 64 32 16 8 4 2 1
-128 64 32 16 8 4 2 1
1

Method 2

  • Step 3 - Make 116

    • Put 1s under each of the numbers that added to -128 make up -116.

 

 

  • Step 4 - put the 0s underneath everything else
-128 64 32 16 8 4 2 1
1 1 1
-128 64 32 16 8 4 2 1
1 0 0 0 1 1 0 0

try it yourself

  • Calculate the following numbers using 8 bit Two’s complement.

    • -120

    • -85

    • -4

    • -1

    • 32

1010 1011

1111 1111

1000 1000

0010 0000

1111 1100

Past Paper Question

Convert the following 8-bit two’s complement number into denary.

 

1001 1010

1 mark

2019 Q1

-102

Important notes

  • With Two’s Compliment Binary:
    • 1000 0000 = -128
    • 0100 0000 = 64
  • If the left most bit is a 1 the number is negative
  • If the left most bit is 0 the number is positive

Complete the Two's complement task sheet

Task

The range of numbers of representable by a number of bits

  • At Higher, we need to be able to calculate the range of numbers that Two’s Compliment can represent given a certain number of bits.

 

  • The way we do that is use the following formula. Where n is the number of bits.

    -2n-1 to (2n-1) – 1

 

  • For example

    -28 -1 to (28 -1) – 1

-128 to 127

Selection

  • Calculate the range of numbers that can be represented using Two’s Compliment if you have:

    1. 10 bits
    2. 12 bits
    3. 16 bits
    4. 24 bits

-512 to 511

-2,048 to 2,047

-32,768 to 32,767

-8,388,608 to 8,388,607

Complete the Range of Numbers task sheet

Task

Floating point

  • Floating point representation is also known as standard form.
  • If we have a number such as 54934.33239, we can represent this with a mantissa and an exponent:
\rlap{$\overbrace{\phantom{5.493433239}}^{mantissa}$}5.493433239\times10\underbrace{^{-4}}_{exponent}

This is the same number as 54934.33239

Floating point

  • At National 5, you need to know:
    • A floating-point number is made of two parts called the mantissa and exponent
    • The mantissa dictates the precision of a number, the more bits allocated to the mantissa, the more precise a number can be
    • If you want to be store a large range of numbers then you need to allocate more bits to the storage of the exponent, as the exponent dictates the range of numbers that can be represented

Answer the following questions:

  1. What is the mantissa in 53.5 x 10-4?
  2. What is the value of the exponent in 54.78 x 104?
  3. How is a real number stored in a computer system?

Review questions

Past Paper Question

1500711

5

The current meter reading of 15007.11 would be stored in a computer system using floating-point representation as shown below.

 

0.1500711 x 105

 

Identify the mantissa and exponent in the above floating-point representation.

 

Mantissa ____________________________________________________

Exponent ___________________________________________________

 

2 marks

Floating point

  • The number 20.125 can be represented as .20125 x 102

     

  • 20.125 can be represented as .20125 x base places point moved

  • But a computer works in Binary so:

20.125 = 10100.001
∴ 10100001 x 25

Floating point

  • At Higher level you will be given a real binary number and be asked to identify the mantissa and exponent.

  • We are going to start by converting real numbers into binary.

Converting Floating-Point to Binary

  • Let's convert 10.75 to floating point.

8 4 2 1
1 0 1 0

First calculate 10 and add the decimal point 

8 4 2 1 0.5 0.25 0.125 0.625
1 0 1 0 1 1 0 0

Now figure out the bit after the decimal place

Convert the following decimal numbers into Binary.
 

  1. 10.5
  2. 8.25
  3. 11.75
  4. 2.875
  5. 15.9375

Try it yourself

8 4 2 1 0.5 0.125 0.625
10.5 1 0 1 0 1 0 0 0
8.25 1 0 0 0 0 1 0 0
11.75 1 0 1 1 1 1 0 0
2.875 0 0 1 0 1 1 1 0
15.9375 1 1 1 1 1 1 1 1

Complete task 1 the Floating Point Representation task sheet

Task

Representation

  • Once we have our decimal number in binary we have to represent it as a floating point number.

  • Let’s take 10.75 (1010.1100). In floating point this would be:

    .1010 1100 × 24
  • We also need to convert the Exponent into a binary number so it then becomes:

    .10101100 × 2100

Mantissa = 1010 1000
Exponent = 100

The exam

  • In an exam you might be given a question like below, so let’s work through it.

 

The decimal number 6.125 converted to binary is 110.001.

 

Convert 110.001 to floating point representation. There are 16 bits for mantissa (including the sign bit) and 8 bits for the exponent.

 

2 marks

 

 

 

 

The exam

  • Step 1: Move the decimal point before the first 1 and write as floating point number:



    110.001 = .110001
     
    • This means it's moved three steps.

  • Step 2: Write as a floating point number
    .110001 x 23

The Exam

  • Step 3: Convert 3 (the number of steps the decimal moved) into a binary number.

8 4 2 1
0 0 1 1
  • Step 4 : Identify Sign bit.

    • The sign bit indicates whether a number is positive or negative.

    • A positive number is represented using a 0

    • A negative number is represented using a 1

    • As our number is positive our sign bit is 0.

The exam

110 001

0 0000 0000

0011

0

  • 0s go to the right as these can be ignored if decimal point put back in
  • 0s go to the left so that there is scope to make the exponent bigger or smaller
  • Step 5: Assign sign bit, mantissa and exponent. Remember we need a 16-bit mantissa (including sign bit) and 8-bit exponent.

0000

Convert the following binary numbers into floating point representation, assigning 16 bits to the mantissa (including sign bit) and 8 bits for the exponent.
 

  1. 1101.1100
  2. 01010.101
  3. - 10.110110
  4. - 111.001000

Try it yourself

Sign Mantissa Exponent
1. 0 110 1110 0000 0000 0000 0100
2. 0 010 1010 1000 0000 0000 0101
3. 1 101 1011 0000 0000 0000 0010
4. 1 111 0010 0000 0000 0000 0011

Complete task 2 & 3 the Floating Point Representation task sheet

Task

Negative Exponent Floating Point

  • Sometimes you might be given a number where you need to move the decimal point to the right instead of the left. For example:

    0.0001101011

  • When you move the decimal point to the right the exponent becomes negative. So our number would be:

    .1101011 x 2-3

Negative Exponent Floating Point

  • Convert the following binary number into Floating Point Representation, assigning 16 bits to the Mantissa (incl. sign bit) and 8 bits for the Exponent.

    0.0000110101

  • Step 1: Move the decimal point so it is before the first 1

    0.0000110101 = .110101

Negative Exponent Floating Point

  • Convert the following binary number into Floating Point Representation, assigning 16 bits to the Mantissa (incl. sign bit) and 8 bits for the Exponent.

    0.0000110101

  • Step 1: Move the decimal point so it is before the first 1

    0.0000110101 = .110101

  • Step 2: Write as a floating point number

    .110101 x 2-4

Negative Exponent Floating Point

  • Convert the following binary number into Floating Point Representation, assigning 16 bits to the Mantissa (incl. sign bit) and 8 bits for the Exponent.

    0.0000110101

  • Step 1: Move the decimal point so it is before the first 1

    0.0000110101 = .110101

  • Step 2: Write as a floating point number

    .110101 x 2-4

  • Step 3: Convert -4 (the number of steps the decimal moved) into a binary number.

-128 64 32 16 8 4 2 1
1 1 1 1 1 1 0 0
  • Step 4 : Identify Sign bit.

    • The sign bit indicates whether a number is positive or negative.

    • A positive number is represented using a 0

    • A negative number is represented using a 1

    • As our number is positive our sign bit is 0.

Complete task 4 & 5 the Floating Point Representation task sheet

Task

Unicode

  • We’ve already seen how numbers are stored in a computer system and that computers can only store numbers as a series of 1s and 0s.

  • When it comes to storing text a computer works in the exact same way. They store text with its own unique binary number

  • Unicode is the standard that has been developed for text representation.

From National 5

  • We should already know from National 5 about Extended ASCII.

  • E-ASCII is an 8 bit character set used to store text.

  • The Extended ASCII system is based on the English alphabet and represents each character using 8 bits (or up to 256 characters). 

  • This is sufficient for 26 upper case letters, 26 lower case letters, a few dozen punctuation characters, the symbols for the digits 0-9, and control characters found in the English language
     

From National 5

  • We should already know from National 5 about Extended ASCII.

  • E-ASCII is an 8 bit character set used to store text.

  • The Extended ASCII system is based on the English alphabet and represents each character using 8 bits (or up to 256 characters). 

  • This is sufficient for 26 upper case letters, 26 lower case letters, a few dozen punctuation characters, the symbols for the digits 0-9, and control characters found in the English language

  • Unfortunately Extended ASCII does not allow us to represent characters from foreign languages for example as we are limited to the 256 characters.

Unicode

  • The Unicode system uses at least 16 bits to represent each character (there are now 32 bit Unicode variations as well).

  • That means we can store and represent 65,356 different characters codes.

  • The table below compares E-ASCII and Unicode

Extended ASCII Unicode
Number of bits 8 16
Pros Takes up less storage space as only using 1 byte for each character Can store and represent 65,356 different characters
Cons Can only store and represent 256 characters Uses twice the storage as Extended ASCII taking up 2 bytes for every character

Past Paper Question

Character sets can be represented using either ASCII or Unicode. 

Describe an advantage of using Unicode over ASCII, making reference to the number of bits used to represent a character in each format.

 

2 marks

2018 Q5

Unicode can represent more characters (216) (1 mark) when compared with ASCII (28 or 27) (1 mark)

Bitmap graphics

  • Bitmapped graphics are a type of graphic that store images as colour code for a two-dimensional grid of pixels.

  • Pixel is a portmanteau of picture and element which are the dots that make up the graphic

  • Bit-depth refers to the number of bits that are used as the code for each pixel. In other words how many bits are assigned to each pixel.

  • An image using 1-bit-depth could represent 2 colours
  • An image using 8-bit-depth could represent 256 colours
  • An image using 16-bit-depth could represent 65,356 colours
  • An image using 24-bit-depth could represent 16,777,216 colours

Resolution

  • Resolution is the number of pixels going across (the width) the image multiplied by the number of pixels going up and down (the height) the image.

  • Bitmapped graphics are resolution dependent. This means that once the resolution is set once the image is created. Increasing the resolution of the image will cause pixelation.

  • Dots-per-inch is another type of measure of resolution. 

Calculations involving bitmaps

  • It's useful to know how the file size of a standard and uncompressed bitmap graphic is calculated and it's really easy to understand.

  • You can use the following formula to calculate it:

filesize = (width\times dpi) \times (height \times dpi) \times bit depth

Advantages and disadvantages of bitmaps

Advantages Disadvantages
Can produce realistic photographic images Have a large file size (compared to vector graphics)
Can edit images at pixel level Resolution is set at point of creation and cannot be increased without a loss of quality (resolution dependent)

Past Paper Questions

The web page uses bit-mapped graphic files for the book covers. 

State one advantage of using bit-mapped graphic files rather than vector graphic files on this web page

 

1 mark

SQP Q19 (e)

  • They produce more realistic photographic images
  • They can be edited at pixel level

Vector graphics

  • Vector graphics store images as a list of objects, each of which is described by its attributes

  • Object attributes include: starting (x, y) co-ordinates, line colour, fill colour, line thickness etc.

  • Vector graphics are resolution independent which means the resolution can be increased without a loss in quality.

Vector graphics

Advantages Disadvantages
Can be scaled without a loss in quality (resolution independent) Cannot edit at pixel level
Can make best use of high-resolution output devices Not suitable if you are looking for photo-realistic images
Vector objects can be edited independently of each other
Can be easily moved/manipulated
Smaller files sizes than bitmapped graphics

Vector graphics vs bitmap graphics

Bitmapped graphics Vector graphics
Larger file sizes Smaller file sizes
All pixels are stored Only objects attributes are stored
Resolution dependent Resolution independent
Overlapping shapes will remove part of the underneath shape Overlapping shapes don’t affect the underneath shape
Editable at pixel level Not editable at pixel level. Only object attributes are editable

Past Paper Question

LottoScot has a logo shown below in diagram 1. They want to change the logo to the one in diagram 2.

 

 

 

 

In diagram 2 the rectangle has been moved forward.

Explain the advantage of making this change using a vector graphic application compared to a bit‑mapped graphic application.

 

2 marks

2022 Q3

With vector individual objects/attributes can be edited/moved independently or objects can be layered whereas in bitmap you can edit individual pixels

Presentation Overview
Close
JB
Data Representation
© 2020 - 2024 J Balfour
13:16 | 29-04-2024
Join Live Session
Start Remote
Save Progress
Slideshow Outline
Presenter Mode
Widget Screen
Canvas Controls
Random Selector
Timer
Volume Meter
Binary Converter
Python Editor
Show Knox 90
Provide Feedback
Help
!
Keywords
    DragonDocs Management
    Random selector
    Sections
      Binary conversion
      Denary to binary conversion
      Binary to denary conversion
      Feedback 👍
      Accessibility

      Apply a filter:

      ×
      All slideshow files