Top Banner
Notes by Liz Ritchard at Rosny College (with some adaptations by Hobart College and Rosny College) Page 1
26

Computer Representation of Numbers · Web viewCode 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

May 06, 2018

Download

Documents

vankiet
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Computer Representation of Numbers · Web viewCode 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

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

Page 1

Page 2: Computer Representation of Numbers · Web viewCode 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

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 Systemdecimal 10 0 1 2 3 4 5 6 7 8 9binary 2 0 1octal 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 Hexadecimal0 00000 0 01 00001 1 12 00010 2 23 00011 3 34 00100 4 45 00101 5 56 00110 6 67 00111 7 78 01000 10 89 01001 11 910 01010 12 A11 01011 13 B12 01100 14 C13 01101 15 D14 01110 16 E15 01111 17 F16 10000 20 10

Note that any base other than 10 must have a subscript to indicate what number system it is.For example: 1210 the 10 indicates the number given uses base 10 (decimal)

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

Page 2

Page 3: Computer Representation of Numbers · Web viewCode 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

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:Eg 1012 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 = 120.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 ResultEg. 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 binary is 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 no 0Does 256 go into 7 no 0Does 128 go into 7 no 0Does 64 go into 7 no 0Does 32 go into 7 no 0Does 16 go into 7 no 0Does 8 go into 7 no 0Does 4 go into 7 yes 1 how many are left over? 7-4=3Does 2 go into 3 yes 1 how many are left over? 3-2=1Does 1 go into 1 yes 1 how 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 ResultEg. 11 0 0 0 0 0 0 1 0 1 1 1011

6

18

27

53

Page 3

Page 4: Computer Representation of Numbers · Web viewCode 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

Page 4

Page 5: Computer Representation of Numbers · Web viewCode 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

CONVERTING THE FRACTIONAL PARTS FROM DECIMAL TO BINARY

eg 1 .2510 = ?2

0.25 2 = 0 + 0.5 first digit = 00.5 2 = 1 + 0 second digit = 1

Giving .2510 = 0.012

NotesOnly the fractional part is multiplied by 2.The process continues until enough digits have been obtained or the fractional part becomes zero.

eg 2 0.110 to binary0.1 2 = 0 + 0.2 first digit = 00.2 2 = 0 + 0.4 second digit = 00.4 2 = 0 + 0.8 third digit = 00.8 2 = 1 + 0.6 fourth digit = 10.6 2 = 1 + 0.2 fifth digit = 10.2 2 = 0 + 0.4 sixth 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 binary5 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

Page 5

Page 6: Computer Representation of Numbers · Web viewCode 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

CONVERTING FROM HEXADECIMAL TO DECIMALTo 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 HEXADECIMALTo 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 BINARYWorking 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

Page 6

Page 7: Computer Representation of Numbers · Web viewCode 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

CONVERTING FROM BINARY TO HEXADECIMALWorking 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 eg 64 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 showa integers greater than 255b negative numbers

Page 7

Page 8: Computer Representation of Numbers · Web viewCode 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

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 15 Most significant bit eg a 16-bit wordBits 1-14 Balance of the wordBit 0 Least 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 - 3910 1 010 01112

+ 3910 0 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 +12710 0111 11112

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

eg with a 4-bit word and sign magnitude

1 1102 = (-)(4 + 2) = -61 0012 = (-)(1) = -10 1012 = (+)(4 + 1) = +5

Note The largest number to be represented in 4 bits is 01112 or + 7There are 2 representations for zero, 00002 and 10002, this is why some older systems gave +0 & -0.

Note We 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.

Page 8

Page 9: Computer Representation of Numbers · Web viewCode 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

“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 value6 0000 0110 1111 1010 -6-6 1111 1010 0000 0110 6

Interpreting numbers in two’s complement representationPositive integersThe most significant bit is “0”.The value is equal to the binary string. For example, 0000 0011 represents 310.

Negative integersThe 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 SYSTEMArithmetic 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

Page 9

Note1 + 0 = 10 + 1 = 1 1 + 1 = 0 + carry of 11 + 1 + 1 = 1 + carry of 1

Page 10: Computer Representation of Numbers · Web viewCode 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

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 110013 Add the resulting binary numbers using ordinary binary addition. 01101

+ 11001------------ 1 00110

4 Truncate any leading 1 (carry) that occurs.  (In this case, a 1 has carried into the extra position.)

1 00110 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 = 001108 = 01000

2 Convert the number to be subtracted to 2's complement form. 01000 110003 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 COMPLEMENTIf 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.

Page 10

Page 11: Computer Representation of Numbers · Web viewCode 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

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 binary show 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 IntegersCode The Represented Number

4-bit Word Unsigned Sign Magnitude

Two's Complement

0000 0 0 00001 1 1 10010 2 2 20011 3 3 30100 4 4 40101 5 5 50110 6 6 60111 7 7 71000 8 -0 -81001 9 -1 -71010 10 -2 -61011 11 -3 -51100 12 -4 -41101 13 -5 -31110 14 -6 -21111 15 -7 -1

Page 11

Page 12: Computer Representation of Numbers · Web viewCode 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

COMPUTER REPRESENTATION OF FLOATING POINT NUMBERS

A floating point number may be represented by 3 parts in a single computer word.m x be where m is the mantissa and 0 <= mantissa < 1

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

eg 67.79 x 10-3

Scientific notation uses one significant digit before the decimal point, multiplied by the base (10) to the appropriate powereg 6.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.eg 0.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 computersFloating 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 Precisionfloat 32 bits 3.4 1038 1.4 10-45 6-7 sig figsdouble 64 bits 1.8 10308 4.9 10-324 14-15 sig figsSome examples of floating point representation with 16 bit wordsThere 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 - 0sign0 (+) exponent in 2's Normalised mantissa1 (-) complement to base 2

Page 12

Page 13: Computer Representation of Numbers · Web viewCode 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

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}

eg1 0 00001 1000000000sign = plus

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

eg2 1 00000 1101000000sign = minus

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

eg3 1 11110 1010000000sign = minus

- - 010 .101 = - .101 x 2-010 mantissa = 0.101= - 0.625 x 2-2 exponent = - 2= - 0.15625

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

15 bits 14 - 6 bits 5 - 0sign0 (+) exponent in 2's Normalised mantissa1 (-) 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.Eg 1 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.eg 4 digit mantissa

.6152 103

- .6151 103 .0001 103 = .1 x 100

.6152 x 105

x .6151 x 105 .3785 x 105 should 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 REPRESENTATIONPage 13

Page 14: Computer Representation of Numbers · Web viewCode 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

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

ImagesAn 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

Page 14

640 wide

480 high

Page 15: Computer Representation of Numbers · Web viewCode 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

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

X-BIT COLOURS16 bit colour24 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 kilobyte153, 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?

SOUNDTo 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?

Page 15

Page 16: Computer Representation of Numbers · Web viewCode 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

SOLUTIONS

Binary Conversions

Number 512 256 128 64 32 16 8 4 2 1 Result1011 0 0 0 0 0 0 1 0 1 1 8+2+1 = 111100 1 1 0 0 8+4= 12

10101 1 0 1 0 1 16+4+1=2111001 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 Result11 0 0 0 0 0 0 1 0 1 1 10116 1 1 0 110

18 1 0 0 1 0 1001027 1 1 0 1 1 1101153 1 1 0 1 0 1 110101

Hexadecimal Conversions

Hexadecimal 16’s 1’s Working Decimal06 0 x16 6 (0 x16) + 6 = 0+6 61A 1 x16 A (1 x16) + A = 16+10 260E 0 x16 E (0 x16) + E = 0+14 1432 3 x16 2 (3 x16) + 2= 48+2 50B5 B x16 5 (B x16) + 5 = (11 x16) + 5 = 176+5 181

Decimal 16’s 1’s Working Hexadecimal18 1 2 18 / 16= 1 (with 2 left over) 1244 2 C 42 / 16 = 2 (with 12 left over – 12 is C) 2C7 0 7 07

25 1 9 25/16 = 1 (with 9 left over) 1913 0 D 0D

Hexadecimal 16’s 1’s Working Binary06 0 x16 6 0000 0000 + 0000 0110 0000 01101A 1 x16 A (10) 0001 0000 + 0000 1010 0001 10100E 0 x16 E (14) 0000 0000 + 0000 1110 0000 111032 3 x16 2 0011 0000 + 0000 0010 0011 0010

Binary 16’s 1’s Hexadecimal0000 0110 0 (0000 0000) 6 (0000 0110) 060001 1100 1 (0001 0000) 12 (0000 1100) 1C0010 0001 2 (0010 0000) 1 (0000 0001) 210001 0111 1 (0001 0000) 7 (0000 0111) 17

TerminologyWhat is meant by the following terms:

Page 16

Page 17: Computer Representation of Numbers · Web viewCode 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

(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 01111 1000 -8 1111 1111 -10000 1111 15 0111 1111 1271111 1001 -7 1000 0000 -128

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

(a) 1 + 1 (b) 1 + 1 + 1 (c) 1 + 1 + 1 + 1 10 11 100

(d) 11 1111 + 1 (e) 101101 + 110111 (f) 11101 + 11011 + 10101100 0000 110 0100 101 101

SubtractionComplete the following subtractions:(a) 3 - 1 (b) 7 - 2 (c) 10 - 12 3 = 000 011 7=000 111 10=001 0101 = 000 001 2= 000 010 12=001 100-1 = 111 111 -2=111 110 -12=110100

000 011 000 111 001 010 111 111 111 110 110 100------------ ------------ ------------1 000 010 1 000 101 111 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 111 13=001 101 15=001 11112=001 100 15=001 111 9= 001 001-12=110100 -15=110 001 -9=110 111

001 111 001 101 001 111 110 100 110 001 110 111------------ ------------ ------------1 000 011 111 110 1 000 110(truncate the carry) (take two’s complement) (truncate the carry)000 011 (3) 000 010 (-2) 000 110 (3)

Page 17

Page 18: Computer Representation of Numbers · Web viewCode 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

Floating Point RepresentationWhat is the computer representation of the following binary numbers?

(a) 0.011 2100 (b) –0.00110 0 000 011 1100 0000 1 1 000 010 1100 0000

(c) 111000 (d) 10.11 2-111

0 0 000 110 1110 0000 1 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.031251000 0000.1 0.0001 1001… 0.00001(requires 9 bits) (recurring number) (precise solution)

Calculating File SizesHow many bits are needed to represent 16 colours? 24 = 16 4 bitsHow 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 bits 1280 x 720 x 10 = 9, 216, 000 bits7, 372, 800 bits /8 = 921, 600 bytes 9, 216, 000 bits /8 = 1, 152, 000 bytes921, 600 bytes /1024 = 900 KB 1, 152, 000 bytes /1024 = 1125 KB900KB /1024 = 0.88MB 1125 KB /1024 = 1.1MB

In MB what is the file size of:A 60 second audio clip, sampled at 44KHz, using 16 bit audio?60 x 44000 x 16 = 42, 240, 000 bits42, 240, 000 bits /8 = 5, 280, 000 bytes5, 280, 000 bytes /1024 = 5, 156.25 KB5, 156.25 KB /1024 = 5 MB

A 1.5 minute audio clip, sampled at 96KHz, using 24 bit audio?90 x 96000 x 24 = 207, 360, 000 bits207, 360, 000 bits /8 = 25, 920, 000 bytes25, 920, 000 bytes /1024 = 25, 312. 5 KB25, 312. 5 KB /1024 = 24.7 MB

Page 18

Page 19: Computer Representation of Numbers · Web viewCode 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

THE ASCII CHARACTER SET

Most programming languages have a means of defining a character as a numeric code and, conversely, converting the code back to the character.ASCII - American Standard Code for Information Interchange. A coding standard for characters, numbers, and symbols that is the same as the first 128 characters of the ASCII character set but differs from the remaining characters.

The ASCII character set (excluding the extended characters defined by IBM) is divided into four groups of 32 characters.

HEX DEC CHR CTRL   HEX DEC CHR   HEX DEC CHR   HEX DEC CHR00 0 NUL ^@   20 32 SP   40 64 @   60 96 `01 1 SOH ^A   21 33 !   41 65 A   61 97 a02 2 STX ^B   22 34 "   42 66 B   62 98 b03 3 ETX ^C   23 35 #   43 67 C   63 99 c04 4 EOT ^D   24 36 $   44 68 D   64 100 d05 5 ENQ ^E   25 37 %   45 69 E   65 101 e06 6 ACK ^F   26 38 &   46 70 F   66 102 f07 7 BEL ^G   27 39 '   47 71 G   67 103 g08 8 BS ^H   28 40 (   48 72 H   68 104 h09 9 HT ^I   29 41 )   49 73 I   69 105 i0A 10 LF ^J   2A 42 *   4A 74 J   6A 106 j0B 11 VT ^K   2B 43 +   4B 75 K   6B 107 k0C 12 FF ^L   2C 44 ,   4C 76 L   6C 108 l0D 13 CR ^M   2D 45   4D 77 M   6D 109 m0E 14 SO ^N   2E 46 .   4E 78 N   6E 100 n0F 15 SI ^O   2F 47 /   4F 79 O   6F 111 o10 16 DLE ^P   30 48 0   50 80 P   70 112 p11 17 DC1 ^Q   31 49 1   51 81 Q   71 113 q12 18 DC2 ^R   32 50 2   52 82 R   72 114 r13 19 DC3 ^S   33 51 3   53 83 S   73 115 s14 20 DC4 ^T   34 52 4   54 84 T   74 116 t15 21 NAK ^U   35 53 5   55 85 U   75 117 u16 22 SYN ^V   36 54 6   56 86 V   76 118 v17 23 ETB ^W   37 55 7   57 87 W   77 119 w18 24 CAN ^X   38 56 8   58 88 X   78 120 x19 25 EM ^Y   39 57 9   59 89 Y   79 121 y1A 26 SUB ^Z   3A 58 :   5A 90 Z   7A 122 z1B 27 ESC     3B 59 ;   5B 91 [   7B 123 {1C 28 FS     3C 60 <   5C 92 \   7C 124 |1D 29 GS     3D 61 =   5D 93 ]   7D 125 }1E 30 RS     3E 62 >   5E 94 ^   7E 126 ~1F 31 US     3F 63 ?   5F 95 _   7F 127 DEL

Page 19