Notes by Liz Ritchard at Rosny College (with some adaptations by Hobart College and Rosny College)

Computer Representation of Numbers

A numbering system is a way of representing numbers. The decimal (base 10) system for counting was used because we have 10 digits (fingers). Computers use the binary (base 2) system because it is easy to produce electronic components which are in one of 2 states (on / off) rather than 10 states. This means that anyone working with computers must be able to work with and understand binary and the related hexadecimal (base 16) systems.

Counting Systems

There are 4 major counting systems used with computers - decimal, binary, octal and hexadecimal. Notice that hexadecimal needs the letters A ..F to give 16 discrete digits.

Counting System / Base / Digits in System
decimal / 10 / 0 1 2 3 4 5 6 7 8 9
binary / 2 / 0 1
octal / 8 / 0 1 2 3 4 5 6 7
hexadecimal / 16 / 0 1 2 3 4 5 6 7 8 9 A B C D E F
Decimal / Binary / Octal / Hexadecimal
0 / 00000 / 0 / 0
1 / 00001 / 1 / 1
2 / 00010 / 2 / 2
3 / 00011 / 3 / 3
4 / 00100 / 4 / 4
5 / 00101 / 5 / 5
6 / 00110 / 6 / 6
7 / 00111 / 7 / 7
8 / 01000 / 10 / 8
9 / 01001 / 11 / 9
10 / 01010 / 12 / A
11 / 01011 / 13 / B
12 / 01100 / 14 / C
13 / 01101 / 15 / D
14 / 01110 / 16 / E
15 / 01111 / 17 / F
16 / 10000 / 20 / 10

Note that any base other than 10 must have a subscript to indicate what number system it is.

For example:1210the 10 indicates the number given uses base 10 (decimal)

011002the 2 indicates the number given uses base 2 (binary)

29 / 28 / 27 / 26 / 25 / 24 / 23 / 22 / 21 / 20 / 2-1 / 2-2 / 2-3 / 2-4 / 2-5 / 2-6
512 / 256 / 128 / 64 / 32 / 16 / 8 / 4 / 2 / 1 / .5 / .25 / .125 / .0625 / .03125 / .015625

Converting from binary to decimal

The easiest way to convert from binary to decimal (with small numbers) is to refer to the table above:

Eg1012 has the value 1 4 + 0 1 + 11= 4 + 0 + 1 = 5

11002 has the value 1 8 + 1 4 + 0 2 + 0 1= 8 + 4 = 12

0.1012 has the value 1 .5 + 0 . 25 + 1 .125 = .5 + .125 = 0.625

Number / 512 / 256 / 128 / 64 / 32 / 16 / 8 / 4 / 2 / 1 / Result
Eg. 1011 / 0 / 0 / 0 / 0 / 0 / 0 / 1 / 0 / 1 / 1 / 8+2+1 = 11
1100
10101
11001
010001

Converting from decimal to binary

The easiest way to convert from decimal to binaryis to refer to the table above (this method uses division):

You look at the decimal number you have been given, and, referring to the table, compare it to each value from left to right.

Eg. The number 7

Does 512 go into 7 no0

Does 256 go into 7  no0

Does 128 go into 7  no0

Does 64 go into 7  no0

Does 32 go into 7  no0

Does 16 go into 7  no0

Does 8 go into 7  no0

Does 4 go into 7  yes1how many are left over? 7-4=3

Does 2 go into 3  yes1how many are left over? 3-2=1

Does 1 go into 1  yes1how many are left over? 1-1=0

The simplest way is to use a copy of the table and put a 1 in each box that fits in the number.

Complete the following table:

Number / 512 / 256 / 128 / 64 / 32 / 16 / 8 / 4 / 2 / 1 / Result
Eg. 11 / 0 / 0 / 0 / 0 / 0 / 0 / 1 / 0 / 1 / 1 / 1011
6
18
27
53

Converting the fractional parts from decimal to binary

eg 1.2510 = ?2
0.25  2 = 0 + 0.5first digit = 0
0.5  2 = 1 + 0second digit = 1
Giving .2510 = 0.012 / Notes
Only the fractional part is multiplied by 2.
The process continues until enough digits have been obtained or the fractional part becomes zero.
eg 20.110 to binary
0.1  2 = 0 + 0.2first digit = 0
0.2  2 = 0 + 0.4second digit = 0
0.4  2 = 0 + 0.8third digit = 0
0.8  2 = 1 + 0.6fourth digit = 1
0.6  2 = 1 + 0.2fifth digit = 1
0.2  2 = 0 + 0.4sixth digit = 0
etc etc.
Writing as a recurring binary number:
0.110 = 0.0001100110011..2
Rounding of to, say, 6 binary points:
0.110 = 0.0001102 / Notes
An exact decimal fraction may not have an exact binary equivalent. For divisions which do not go exactly go to one more place than asked for, then round.
The decimal number 0.1 cannot be represented exactly in binary. It must be rounded off to a finite number of decimal places, giving rise to round-off error.
eg 3 5.125 to binary
5 becomes 101 in binary
.125  2 = 0 + .25 first digit = 0
.25  2 = 0 + .5 second digit = 0
.5  2 = 1 + 0 third digit = 1
Thus 5.12510 = 101.0012

Hexadecimal

Hexadecimal uses a base of 16 and to provide that we go beyond the 0-9 digits and use characters A-F.

Decimal / 0 / 1 / 2 / 3 / 4 / 5 / 6 / 7 / 8 / 9 / 10 / 11 / 12 / 13 / 14 / 15
Hexadecimal / 0 / 1 / 2 / 3 / 4 / 5 / 6 / 7 / 8 / 9 / A / B / C / D / E / F

Converting from hexadecimal to decimal

To convert between decimal and hexadecimal, you can use a similar approach to binary, using column values, but rather than simply adding the items together, there is an additional multiplication. We will stick with two digit hexadecimal conversion

Hexadecimal / 16’s / 1’s / Working / Binary
06 / 0 x16 / 6 / (0 x16) + 6 = 0+6 / 6
1A / 1 x16 / A / (1 x16) + A = 16+10 / 26
0E
32
B5

Converting from decimal to hexadecimal

To convert from decimal to hexadecimal, we can divide the number by 16, the whole number is the number of 16’s in the number. If you subtract the 16’s from the original problem, the number of whole numbers remaining is the 1’s in the number.

Binary / 16’s / 1’s / Working / Hexadecimal
18 / 1 / 2 / 18 / 16= 1 (with 2 left over) / 12
44 / 2 / C / 42 / 16 = 2 (with 12 left over – 12 is C) / 2C
7
25
13

Converting from hexadecimal to binary

Working similarly to the decimal conversion, we can then use the 16’s and 32’s columns for the number of 16’s in a number, and convert the remainder in normal binary

Hexadecimal / 16’s / 1’s / Working / Binary
06 / 0 x16 / 6 / 0000 0000 + 0000 0110 / 0000 0110
1A / 1 x16 / A (10) / 0001 0000 + 0000 1010 / 0001 1010
0E
32

Converting from binary to hexadecimal

Working similarly to the decimal conversion, we can then use the 16’s and 32’s columns for the number of 16’s in a number, and convert the remainder in normal binary

Binary / 16’s / 1’s / Working / Hexadecimal
0000 0110 / 0
(0000 0000) / 6
(0000 0110) / 06
0001 1100 / 1
(0001 0000) / 12
(0000 1100) / 1C
0010 0001
0001 0111

Storing Integers (ie. whole numbers) in the computer

The basic unit for storing data in the computer is the bit.

Generally 8 bits = 1 byte.

(half a byte is a nibble, which can be represented by a single hexadecimal digit)

1 Kilobyte = 1024 bytes = 8192bits

eg64 Kb = 64 x 1024 = 65,535 memory locations.

ASCII code uses 7 bits to represent a character, EBCDIC code uses 8 bits.

See back of booklet for ASCII table.

What is meant by the following terms:

(a) bit

(b) nibble

(c) byte

(d) word

Unsigned Binary Numbers

It wastes storage to represent numbers character by character, because one byte is used for each digit. So numbers are converted to binary and represented in that form.

One 8-bit byte can represent numbers ranging from:

0000 00002 = 010 to 1111 11112 = 25510

This range is not generally large enough to show

aintegers greater than 255

bnegative numbers

The group of bits that the computer handles as a whole is referred to as a word (ie a 16-bit machine can handle 16 bits at a time).

15 / 1-14 / 0

Bit 15Most significant biteg a 16-bit word

Bits 1-14Balance of the word

Bit 0Least significant bit

The largest integer in a 16-bit word is 216 - 1 (65535).

To show larger integers you need a longer word but there is always some fixed limit to integer size and the need for a larger integer would cause the system to break down.

If it is not possible to store the results of an operation the system 'overflows' the register provided, this is arithmetic overflow which causes the system to crash with an error message.

There are two main methods of storing Signed Numbers.

Sign Magnitude

To be able to represent negative or positive numbers, the most significant bit is reserved as the sign bit with “0” representing + (positive) and “1” representing – (negative).

eg- 39101 010 01112

+ 39100 010 01112

So instead of being able to represent integers from 0 - 255, with an 8-bit word you can represent integers from

-12710 1111 11112

to+127100111 11112

With a 16-bit word the maximum integer range is -32767 to +32767.

eg with a 4-bit word and sign magnitude

11102= (-)(4 + 2)=-6

10012= (-)(1)=-1

01012= (+)(4 + 1)=+5

NoteThe largest number to be represented in 4 bits is 01112 or + 7

There are 2 representations for zero, 00002 and 10002, this is why some older systems gave +0 & -0.

NoteWe cannot perform arithmetic directly in sign magnitude representation because it would need a machine that has separate addition and subtraction hardware to take care of the sign bits. To overcome this 2's complement representations are used. Subtraction is done by adding the complement of the number, and treating all the bits the same without considering the sign of the value.

Two's Complement

The two’s complement of a number is the negative representation of a number.

This is particularly important for subtraction, as a computer cannot subtract. So when we wish to do subtraction we need to be able to add the opposite (negative representation) of a number.

“Taking a two’s complement” means simply getting the representation of the negative value of a stored number. The easiest way to do this:

Start from the right of the number and work towards the left.

Any ‘0’ bits remain the same until the first ‘1’ bit and the first ‘1’ bit remains the same.

After the first ‘1’ bit all subsequent bits are reversed.

Examples (assuming an 8 bit two’s complement representation):

Original / Binary representation / 2’s complement / New value
6 / 0000 0110 / 1111 1010 / -6
-6 / 1111 1010 / 0000 0110 / 6

Interpreting numbers in two’s complement representation

Positive integers

The most significant bit is “0”.

The value is equal to the binary string. For example, 0000 0011 represents 310.

Negative integers

The most significant bit is “1”.

To obtain the value, “take a two’s complement”. For example 11110110 represents a negative value. Taking a two’s complement gives 00001010 which represents the positive number 610. Hence 11110110 represents –610.

Complete the following table in which 8 bit two’s complement representations are matched with their decimal value.

Binary (two’s complement notation) / Decimal / Binary (two’s complement notation) / Decimal
0000 1101 / 0000 0000
1111 1000 / 1111 1111
15 / 127
-7 / -128

Arithmetic in the Binary System

Arithmetic in binary follows exactly the same rules as for decimal arithmetic.

Addition

Addition (Check by decimal conversion)

eg 1101 13

+ 1110+ 14

11011 27

Complete the following additions, in which all numbers are unsigned binary:

(Note: only add two numbers at a time)

(a) 1 + 1 (b) 1 + 1 + 1 (c) 1 + 1 + 1 + 1

(d) 111111 + 1 (e) 101101 + 110111 (f) 11101 + 11011 + 10101

Subtraction

Subtraction (Check by decimal addition)

Subtraction is done by taking the two’s complement of the number to be subtracted and/or a negative number.

For this to function effectively you must be using more bits than is required to represent the number(allowing for at least a sign bit, it is good practice to have at least 2 extra bits)

For example, to perform the subtraction 13 - 7:

1 / Convert both integers to binary. Remember to add an extra bit to hold the sign. (13 = 1101, then add 1 bit to get 01101.) Both numbers need to be represented with the same number of bits. / 13 = 01101
7 = 00111
2 / Convert the number to be subtracted to 2's complement form. / 00111  11001
3 / Add the resulting binary numbers using ordinary binary addition. / 01101
+ 11001
------
100110
4 / Truncate any leading 1 (carry) that occurs. (In this case, a 1 has carried into the extra position.) / 100110  00110
5 / Convert the result back to decimal form. If the leftmost position is a 0, the number is positive. If the leftmost position is a 1, the number is in 2's complement form; convert the number back by taking the 2's complement of it, then convert to decimal and take the negative. / 00110 = 6

For example, to perform the subtraction 6 - 8:

1 / Convert both integers to binary. Remember to add an extra bit to hold the sign. (6= 0110, then add 1 bit to get 00110.) Both numbers need to be represented with the same number of bits. / 6 = 00110
8 = 01000
2 / Convert the number to be subtracted to 2's complement form. / 01000  11000
3 / Add the resulting binary numbers using ordinary binary addition. / 00110
+ 11000
------
11110
4 / Truncate any leading 1 (carry) that occurs. (In this case, a 1 has carried into the extra position.) / 11110
(no carry in this case)
5 / Convert the result back to decimal form. If the leftmost position is a 0, the number is positive. If the leftmost position is a 1, the number is in 2's complement form; convert the number back by taking the 2's complement of it, then convert to decimal and take the negative. / 11110  00010
(two’s complement)
00010 = -2

Overflow in two’s complement

If the expected answer for a calculation is outside the two’s complement range the calculation results in an overflow error which will affect the most significant bit of the answer: it the expected answer is positive the two’s complement representation with an overflow error will indicate a negative value and vice versa. The following examples will illustrate this.

3 0011
+ 7 0111
10 1010 = -6 in two’s complement
In this example, the expected answer of 10 is outside the 4 bit two’s complement range of –8 to +7 so the answer (in two’s complement interpretation) is incorrect. / - 2 1110
- 7+1001
-9 (1)0111 = +7 in two’s complement
(ignore carry)
In this example, the expected answer of –9 is outside the 4 bit two’s complement range of –8 to +7 so the answer is again incorrect.

Remember: Overflow and Carry are two entirely different concepts. Carry is ignored in two’s complement arithmetic. Overflow indicates a genuine error.

Complete the following subtractions, using 6 bit binaryshow all working & indicate where any errors occur:

(a) 3 - 1(b) 7 - 2(c) 10 - 12

(d) 15 - 12 (e) 13 - 15(f) 15 – 9

A Summary Table Showing the Different Codes for the Integers

Code / The Represented Number
4-bit Word / Unsigned / Sign Magnitude / Two's Complement
0000 / 0 / 0 / 0
0001 / 1 / 1 / 1
0010 / 2 / 2 / 2
0011 / 3 / 3 / 3
0100 / 4 / 4 / 4
0101 / 5 / 5 / 5
0110 / 6 / 6 / 6
0111 / 7 / 7 / 7
1000 / 8 / -0 / -8
1001 / 9 / -1 / -7
1010 / 10 / -2 / -6
1011 / 11 / -3 / -5
1100 / 12 / -4 / -4
1101 / 13 / -5 / -3
1110 / 14 / -6 / -2
1111 / 15 / -7 / -1

Computer Representation of Floating Point Numbers

A floating point number may be represented by 3 parts in a single computer word.

m x be wherem is the mantissa and 0 <= mantissa < 1

b is the base

e is the exponent (the power of the base as a positive or negative integer)

eg67.79 x 10-3

Scientific notation uses one significant digit before the decimal point, multiplied by the base (10) to the appropriate power

eg6.779 x 10-2

Normalised notation has no significant digits before the decimal point, multiplied by the base (10) to the appropriate power. Floating point numbers are stored in normalised form as this is the most efficient way.

eg0.6779 x 10-1

Examples of normalisation (decimal and binary)

0.00156 x 10-4=.156 x 10-6

1732.1=.17321 x 104

794 x 10-5=.794 x 10-5+3

=.794 x 10-2

1101 x 2100 {4}=.1101 x 2100+100 {4+4}

=.1101 x 21000{8}

1101.001 x 2-111{-7}=.1101001 x 2-111+100 {-7+4}

=.1101001 x 2-011{-3}

Helpful hints

If you increase the size of the mantissa (ie move the decimal point to the right) then decrease the size of the exponent by the same number of places (ie subtract the powers).

If you decrease the size of the mantissa (ie move the decimal point to the left) then increase the size of the exponent by the same number of places (ie add to the powers).

Representation of floating point numbers in computers

Floating point numbers require the computer to store the mantissa, exponent and sign. There needs to be a balance between the precision (basically determined by the number of bits in the mantissa), the range (basically determined by the number of bits in the exponent) and the total memory required to store the number. In Java for example the types of real numbers that can be stored are:

Type / Size / Largest Value / Smallest Value / Precision
float / 32 bits /  3.4  1038 /  1.4  10-45 / 6-7 sig figs
double / 64 bits /  1.8  10308 /  4.9  10-324 / 14-15 sig figs

Some examples of floating point representation with 16 bit words

There are many possible ways of storing real numbers, and here are examples of just a few that you might come across in books and in examination questions.

Example 1 – 16 bit word with 5 bit 2’s complement exponent and normalised mantissa

15 / bits 14 - 10 / bits 9 - 0
sign
0 (+) / exponent in 2's / Normalised mantissa
1 (-) / complement to base 2

Largest number that can be represented: 0 01111 1111111111  0.1111111111  21111 {15}

Smallest positive number that can be represented: 0 10000 1000000000  0.1  2-10000 {-16}

eg10 00001 1000000000

sign= plus

+ 1 .1= + .1 x 21 mantissa= 0.1

= + 0.5 x 21 = 1exponent= + 1

eg21 00000 1101000000

sign= minus

- 0 .1101= - .1101 x 20mantissa= 0.1101

= - 0.8125 x 20exponent= 0

= - 0.8125

eg31 11110 1010000000

sign= minus

- - 010 .101= - .101 x 2-010mantissa= 0.101

= - 0.625 x 2-2exponent= - 2

= - 0.15625

Example 2 – 16 bit word with 9 bit 2’s complement exponent and normalised mantissa

15 / bits 14 - 6 / bits 5 - 0
sign
0 (+) / exponent in 2's / Normalised mantissa
1 (-) / complement to base 2

Largest number that can be represented: 0 011111111 111111  0.111111  211111111 {511}

Smallest positive number that can be represented: 0 100000000 100000  0.1  2-100000000 {-512}

This representation has a much greater range but a smaller precision than the previous representation.

Eg1 000000011 110000

Sign= minus

Problems representing floating point numbers

Floating point numbers are very often an inexact representation. Many decimal numbers such as 0.1 and 0.2 are recurring binary fractions and cannot be represented exactly. Also when carrying out calculations the size of the mantissa changes.

eg4 digit mantissa

.6152  103

- .6151  103

.0001 103= .1 x 100

.6152 x 105

x .6151 x 105

.3785 x 105should be .378471 so there is a loss of precision

JAVA uses float to represent floating point numbers, and double to represent numbers of double precision, which uses twice the number of significant figures and also uses more memory.

Floating point representation

In the following problems, use the standard 16 bit representation which has 1 exponent sign digit, 1 mantissa sign digit, 6 exponent digits and 8 mantissa digits (normalised).

What is the computer representation of the following binary numbers using the above system?

(a) 0.011  2100(b) –0.0011

(c) 111000 (d) 10.11  2-111

Floating point roundoff:

When using an 8 bit two’s complement representation. Which of the following decimal numbers can be represented precisely (that is, without any roundoff).

(a) 128.5(b) 0.1(c) 0.03125

Calculation of file sizes

Images

An image has a width in pixels and a height in pixels. Start by calculating the number of pixels all up

640 x 480= 307,200 pixels

Each pixel in the picture represents a colour.
When referring to colours we will either say:

- X colours
- X-bit colour

X Colours

If the image is plain black and white (no grey) then it uses 1 bit to represent each pixel
How many bits are needed to represent 16 colours?
How many bits are needed to represent 256 colours?

X-bit Colours

16 bit colour
24 bit colour
(We are told the number of bits required to produce the colour)

So to calculate the file size we multiply the number of pixels by the number of bits to represent each pixel

640 x 480= 307,200 pixels

Using 16 colours = 4 bits

307,200 x 4 = 1, 228, 800 bits

We need to find out what 1, 228, 800 bits is in Kilobytes

There are 8 bits in a byte:
1, 228, 800 bits / 8 = 153, 600 bytes
There are 1024 bytes in a kilobyte
153, 600 bytes / 1024 = 150 kB
If we needed to calculate Megabytes, we would divide by 1024 again.

In MB what is the file size of:
An image 640 x 480 in 24 bit colour?

An image 1280 x 720 using 1024 colours?

Sound

To calculate the size of a sound file we multiply the:
Time length of the audio clip.eg. 20 second
The rate at which it was sampled. eg. 4 kHz (remember that kilo means 1000!!)
The audio quality. eg. 8 bit audio

20 seconds x (4KHz x 1000)hertz x 8 bit = 640, 000 bits
640, 000 bits /8 = 80, 000 bytes
80, 000 bytes /1024 = 78.1 kB

In MB what is the file size of:
A 60 second audio clip, sampled at 44KHz, using 16 bit audio?

A 1.5 minute audio clip, sampled at 96KHz, using 24 bit audio?
Solutions

Binary Conversions

Number / 512 / 256 / 128 / 64 / 32 / 16 / 8 / 4 / 2 / 1 / Result
1011 / 0 / 0 / 0 / 0 / 0 / 0 / 1 / 0 / 1 / 1 / 8+2+1 = 11
1100 / 1 / 1 / 0 / 0 / 8+4= 12
10101 / 1 / 0 / 1 / 0 / 1 / 16+4+1=21
11001 / 1 / 1 / 0 / 0 / 1 / 16+8+1=25
010001 / 0 / 1 / 0 / 0 / 0 / 1 / 16+1=17
Number / 512 / 256 / 128 / 64 / 32 / 16 / 8 / 4 / 2 / 1 / Result
11 / 0 / 0 / 0 / 0 / 0 / 0 / 1 / 0 / 1 / 1 / 1011
6 / 1 / 1 / 0 / 110
18 / 1 / 0 / 0 / 1 / 0 / 10010
27 / 1 / 1 / 0 / 1 / 1 / 11011
53 / 1 / 1 / 0 / 1 / 0 / 1 / 110101

Hexadecimal Conversions

Hexadecimal / 16’s / 1’s / Working / Decimal
06 / 0 x16 / 6 / (0 x16) + 6 = 0+6 / 6
1A / 1 x16 / A / (1 x16) + A = 16+10 / 26
0E / 0 x16 / E / (0 x16) + E = 0+14 / 14
32 / 3 x16 / 2 / (3 x16) + 2= 48+2 / 50
B5 / B x16 / 5 / (B x16) + 5 = (11 x16) + 5 = 176+5 / 181
Decimal / 16’s / 1’s / Working / Hexadecimal
18 / 1 / 2 / 18 / 16= 1 (with 2 left over) / 12
44 / 2 / C / 42 / 16 = 2 (with 12 left over – 12 is C) / 2C
7 / 0 / 7 / 07
25 / 1 / 9 / 25/16 = 1 (with 9 left over) / 19
13 / 0 / D / 0D
Hexadecimal / 16’s / 1’s / Working / Binary
06 / 0 x16 / 6 / 0000 0000 + 0000 0110 / 0000 0110
1A / 1 x16 / A (10) / 0001 0000 + 0000 1010 / 0001 1010
0E / 0 x16 / E (14) / 0000 0000 + 0000 1110 / 0000 1110
32 / 3 x16 / 2 / 0011 0000 + 0000 0010 / 0011 0010
Binary / 16’s / 1’s / Hexadecimal
0000 0110 / 0  (0000 0000) / 6 (0000 0110) / 06
0001 1100 / 1 (0001 0000) / 12  (0000 1100) / 1C
0010 0001 / 2 (0010 0000) / 1  (0000 0001) / 21
0001 0111 / 1 (0001 0000) / 7  (0000 0111) / 17

Terminology

What is meant by the following terms:

(a) bit – A single bit of information (0 or 1)

(b) nibble – A 4 bit string of bits (also the size of one hexadecimal digit)

(c) byte – An 8 bit string of bits

(d) word–Refers to a string of bits used in a process by a computer. Eg. A computer might work in 8, 16, 32 or 64 bit words. A 16-bit word is commonly used. Many operating systems work on 32 or 64 bit instruction size.

Two’s Complement

Complete the following table in which 8-bit two’s complement representations are matched with their decimal value.

Binary (two’s complement notation) / Decimal / Binary (two’s complement notation) / Decimal
0000 1101 / 13 / 0000 0000 / 0
1111 1000 / -8 / 1111 1111 / -1
0000 1111 / 15 / 0111 1111 / 127
1111 1001 / -7 / 1000 0000 / -128

Addition

Complete the following additions, in which all numbers are unsigned binary:

(a) 1 + 1 (b) 1 + 1 + 1 (c) 1 + 1 + 1 + 1

1011100

(d) 11 1111 + 1 (e) 101101 + 110111 (f) 11101 + 11011 + 10101

100 0000110 0100101 101

Subtraction

Complete the following subtractions:

(a) 3 - 1(b) 7 - 2(c) 10 - 12

3 = 000 0117=000 11110=001 010

1 = 000 0012= 000 01012=001 100

-1 = 111 111-2=111 110-12=110100

000 011 000 111001 010

111 111 111 110110 100

------

1 000 0101 000 101111 110

(truncate the carry)(truncate the carry)(take two’s complement)

000 010 (2)000 101 (5)000 010 (-2)

(d) 15 - 12 (e) 13 - 15(f) 15 – 9

15=001 11113=001 10115=001 111

12=001 10015=001 1119= 001 001

-12=110100-15=110 001-9=110 111

001 111001 101 001 111

110 100110 001 110 111

------

1 000 011111 1101 000 110

(truncate the carry)(take two’s complement) (truncate the carry)

000 011 (3)000 010 (-2)000 110 (3)

Floating PointRepresentation

What is the computer representation of the following binary numbers?

(a) 0.011  2100(b) –0.0011

0 0 000 011 1100 00001 1 000 010 1100 0000

(c) 111000 (d) 10.11  2-111

0 0 000 110 1110 00001 0 000 101 1011 0000

Floating point roundoff:

When using an 8 bit two’s complement representation. Which of the following decimal numbers can be represented precisely (that is, without any roundoff).

(a) 128.5(b) 0.1(c) 0.03125

1000 0000.10.0001 1001…0.00001
(requires 9 bits)(recurring number)(precise solution)

Calculating File Sizes
How many bits are needed to represent 16 colours?24 = 16  4 bits
How many bits are needed to represent 256 colours?28 = 256  8 bits
In MB what is the file size of:

An image 640 x 480 in 24 bit colour?An image 1280 x 720 using 1024 colours?
640 x 480 x 24 = 7, 372, 800 bits1280 x 720 x 10 = 9, 216, 000 bits
7, 372, 800 bits /8 = 921, 600 bytes9, 216, 000 bits /8 = 1, 152, 000 bytes
921, 600 bytes /1024 = 900 KB1, 152, 000 bytes /1024 = 1125 KB
900KB /1024 = 0.88MB1125 KB /1024 = 1.1MB

In MB what is the file size of: