Professional Documents
Culture Documents
Lesson Plan: Data Types and Data Representation
Lesson Plan: Data Types and Data Representation
2
Definitions of Data and Information
Data: Data usually refers to raw data, or
unprocessed data. It is the basic form of data
that hasn’t been analyzed or processed in any
manner.
Examples
• 3
• 40
• 589
• 4356
• -15
• -87690, etc
• A number with a decimal is referred to as
a floating point number. Examples: 5.0,
132.57, etc.
• Character data types include letters, numerical
digits, common punctuation marks (such as ‘.’
or ‘-’), and whitespace.
Data Representation
Data representation considers how a
computer uses numbers to represent data
inside the computer. Computers store lots of
different types of information such as numeric
data, text, images, audio, and video.
Computers use a variety of different codes. Some
are used for numbers, others for text, and still
others for sound and graphics.
16 0 (2^16) – 1 = 65,535
32 0 (2^32) – 1 = 4,294,967,295
64 0 (2^64) – 1 = 18,446,744,073,709,551,615
The larger the number we wish to represent,
the more bits we require. Thus we can
represent more numbers with 16 bits than we
can with 8 bits.
One’s complement
Using 4 bits, say, the one’s complement of a 4
bit binary number is found by changing 0s to
1s and 1s to 0s. For example, the 4-bit one’s
complement of 0110 is 1001.
Note that if we were asked for the 4-bit one’s
complement of 112, we would need to write 11 as
00112 (expand 112 to 4 bits) and then change 0s to 1s
and 1s to 0s, giving 11002 as the 4-bit one’s
complement of 112.
It is important to know that it is wrong to simply say
‘one’s complement of 011’; we must specify how many
bits are involved by saying, for instance, ‘the 4-bit one’s
complement of 011’. It is interesting to note that:
the 3-bit one’s complement of 011 is 100, and
the 4-bit one’s complement of 011 is 1100.
Things to notice:
1. Any negative number will have a 1 in the
MSB.
2. There are 2 representations for 0:
0000 and 1111.
Two’s complement
A variation on 1's complement that does NOT
have 2 representations for 0. This makes the
hardware that does arithmetic faster than for
the other representations.
The two’s complement of a binary number is obtained by
adding 1 to its one’s complement. For example, the 4-bit
one’s complement of 0110 is 1001. Therefore, the 4-bit
two’s complement of 0110 is 1001+1 = 1010.
Suppose we wanted to store integers using 4-bits.
Remember that with 4 bits, we can have 16 different
binary sequences from 0000 to 1111. Therefore we can
represent 16 different integers using 4 bits. Of the 16
different patterns, 8 begin with 0 and 8 begin with 1.
Those beginning with 0 represent positive integer and
those beginning with 1 represent negative integer.
Problem 1: Find the two-byte integer
representation of 105
Unsigned method: 0 to 2n – 1
Sign-magnitude method: - (2n-1 – 1) to (2n-1 – 1)
Two’s complement method: -2n-1 to 2n-1 – 1
1. What decimal number does the two’s
complement number 1010 represent?
2. What decimal number does the two’s
complement number 1110 represent?
3. What decimal number does the two’s
complement number 1010 represent?
4. Using 2‘s complement, represent -15 in 8
bits.
5. Using 2‘s complement, represent -240 in 8
bits.
• Which of these represents -3 as a five bit two’s
complement number?
A. 00011
B. 10011
C. 11100
D. 11101
• Given a 5 bit two’s complement number, what
is the largest positive value you can represent?
A. 5
B. 7
C. 15
D. 31