Google
 
Site navigation: [ Home | Theory | Java | About ]

Data Representation

This idea and some of the questions that follow are based on the concept material in the manual for Computer Science Course 103, © The University of Waikato , 2003 by Professor Ian H Whitten and others .

Since "the others" include me and "they" are still using "my" notes for the course I don't feel too bad about this :-)

 

 

 



On this page: [ binary | negative numbers | characters | pictures | units of bits/bytes ]

This Applet simulates the physical card deck we use in our lessons. The Applet source code is here. If you have trouble seeing the Applet, download the free jre from http://www.java.sun.com or use the Flash Version (requires Flash Player)..

Make the sequence 0 1 1 0 1. The zero represents the card when it is face down and therefore whether the value of the card is to be counted. Therefore the binary number 01101 is equivalent to the decimal number 13.

1
By flipping the cards, show how to make just 5 faces show, try 3, 12, 19. Is there more than one way to get any number?
2
What are the highest and lowest numbers you can make?
3
If we added another card, how many bits would it have? What is the biggest number we can make then?
4
What day of the month were you born on? Make it in using the cards.

Back to top

Binary
We have used 5 cards here; normally binary bits are grouped in sets of 8 called a byte:

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

The above represents decimal 22. Notice that by convention we usually show the leading zeroes in a binary number (although we don't usually write 000022 for decimals).

5
What is the largest number we can have in this system?
We can have 2 different combinations with 1 bit (0 and 1); we can have 4 different combinations with 2 bits (00, 01, 10 and 11).
6
How many different combinations of 8 bits can we have?
7
What is the relationship between the number of bits and the number of different possible combinations?

Back to top

Negative numbers
How can negative numbers be represented? As it turns out there are many ways but probably the two most popular are sign and magnitude and two's complement.

Two's Complement
In this system the most significant bit (on the far left) is the same value as normal but negative:

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

8
How do you represent -22 in this system?
9
What is the most negative number you can have?
10
What is the largest positive number you can have?

One advantage of this system is that we can subtract binary numbers by adding a negative one to a positive one. This is quite easily done with electronic circuitry.

Back to top

Characters
So far we've seen how numbers can be stored in the computer but character data is important to - otherwise we could not type in text or see writing on the monitor.

Characters are often represented using ASCII (American Standard Code for Information Interchange). In this system, every character (even some that don't print) has its own binary code:

character
128
64
32
16
8
4
2
1
A
0
1
0
0
0
0
0
1
B
0
1
0
0
0
0
1
0
<space>
0
0
0
1
0
1
0
0

11 How many different characters can be stored?
12 Why do you think characters that don't print are needed? What could they do?
13 Recently, a new system has been introduced called UNICODE which has 16 bits rather than 8; why do you think that this was needed?

Back to top

Pictures
We are used to the idea of computer graphics. How can a picture be stored in 1's and 0's? A picture in the computer is composed of small elements called pixels, these are square or rectangular and each one can hold only one colour.

If we only want to represent two colours (black and white, say) we need only 1 bit per pixel:

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

14
What do you "see" here? Ho, ho. (try shading the 1's in black if it gives you trouble)

15
If we want to represent 8 shades of gray , how many bits per pixel do we need
16
If we want to represent 256 different colours how many bits per pixel do we need?
That's the same as a GIF image seen on a website.
17
Often on modern computers 24-bit colour is used. How many different colours can be represented in this system?

Back to top

Measuring Computer Memory
The term bit refers to the individual 1 or 0, denoted by the symbol of the single letter b.

The term byte refers to the standard grouping of 8bits into a single unit denoted by the single letter capital B .

Thus 4 Mb of memory is very different to 4 MB of memory.

In the decimal system, we often see the following measurements used:

Tera (T) 1,000,000,000,000
Giga (G) 100,000,000
Mega (M) 1,000,000
kilo (k) 1,000

In computing the measurements such as K are slightly different to those shown above in the table since the computer operates on the binary system.

For example 1 KB = 1024 (2 10 ) bytes; often we use the term KB as an approximation for 1000
bytes. Strictly speaking, the following terms are defined for computer memory.

Tera (T) 240
Giga (G) 230
Mega (M) 220
kilo (k) 210

Back to top

related: [ Core home | previous: languages | next: number systems ]

Here is a link to the worksheet (pdf) we use with the cards.

Here is the same thing in Flash (in case of Applet trouble); opens in a new browser window.


 
The site is partly financed by advertising revenue, partly by online teaching activities and partly by donations. If you or your organisation feel these resouces have been useful to you, please consider a donation, $9.95 is suggested. Please report any issues with the site, such as broken links, via the feedback page, thanks.

Questions or problems related to this web site should be addressed to Richard Jones who asserts his right to be identified as the author and owner of these materials - unless otherwise indicated. Please feel free to use the material presented here and to create links to it for non-commercial purposes; an acknowledgement of the source is required by the Creative Commons licence. Use of materials from this site is conditional upon your having read the additional terms of use on the about page and the Creative Commons Licence. View privacy policy.

Creative Commons License


This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License. © 2001 - 2009 Richard Jones, PO BOX 246, Cambridge, New Zealand;
This page was last modified: October 28, 2013