the teacher cp4 binary and all that… cp4 revision

15
The Teacher CP4 Binary and all that… CP4 Revision

Upload: gwenda-carroll

Post on 02-Jan-2016

249 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: The Teacher CP4 Binary and all that… CP4 Revision

The TeacherCP4

Binary and all that…

CP4 Revision

Page 2: The Teacher CP4 Binary and all that… CP4 Revision

The TeacherCP4

• Binary is a Base 2 Number System

• Only uses digits 0 and 1

• Each digit is called a BIT – short for Binary digIT

The Binary Number System

Page 3: The Teacher CP4 Binary and all that… CP4 Revision

The TeacherCP4

Hexadecimal

• Shorthand way of writing binary numbers

• Base 16 number system

• Uses digits 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F

• Each hex digit represents a 4-bit binary number.

• 6 = 0110

• C = 1100

Page 4: The Teacher CP4 Binary and all that… CP4 Revision

The TeacherCP4

Hex Exercise

1. Convert 011010100011111016 into hex

2. Convert B216 into binary

Page 5: The Teacher CP4 Binary and all that… CP4 Revision

The TeacherCP4

Characters

• Each character has a unique binary code.

• Most commonly used system is ASCII

• A = 01000001

• B = 01000010

• C = 01000011

• etc

Page 6: The Teacher CP4 Binary and all that… CP4 Revision

The TeacherCP4

Positive Integers

• Calculate using the headings…

128 64 32 16 8 4 2 1

Example : Binary representation of 7410

128 64 32 16 8 4 2 1

0 1 0 0 1 0 1 0

Page 7: The Teacher CP4 Binary and all that… CP4 Revision

The TeacherCP4

Negative Integers

• Two methods :– Sign and Magnitude– Two’s Complement

Page 8: The Teacher CP4 Binary and all that… CP4 Revision

The TeacherCP4

Sign and Magnitude

• First bit is a Sign bit (0 for Positive; 1 for Negative).

• Remaining bits are the Size of the integer.

Sign 64 32 16 8 4 2 1

1 0 0 1 0 1 0 1

Example : -21

Page 9: The Teacher CP4 Binary and all that… CP4 Revision

The TeacherCP4

Two’s Complement

• Three steps…– Treat as positive– Change all bits– Add 1

128 64 32 16 8 4 2 1

0 0 0 1 0 1 1 0

Example : -22

Step 1 :

Step 2:128 64 32 16 8 4 2 1

1 1 1 0 1 0 0 1

Step 3:

+1

1 1 1 0 1 0 1 0

Page 10: The Teacher CP4 Binary and all that… CP4 Revision

The TeacherCP4

Real Numbers

• Two methods –– Fixed Point – Floating Point

Page 11: The Teacher CP4 Binary and all that… CP4 Revision

The TeacherCP4

Fixed Point

• The position of the binary point remains fixed.• Eg.: 4 points for the Integer part and 4 bits for

the fraction…

S 4 2 1 1/2 1/4 1/8 1/16

0 1 0 1 . 0 1 0 0

= 5.25

Page 12: The Teacher CP4 Binary and all that… CP4 Revision

The TeacherCP4

Floating Point

• Floating Point Format –

Mantissa x 2 Exponent

Mantissa is a Signed Fraction (Fixed Point)

Exponent is a Signed Integer

Page 13: The Teacher CP4 Binary and all that… CP4 Revision

The Teacher

Convert a real to Floating Point Form

• Example : 9.75• Convert into fixed point binary number…

• Add 0 bits on the right until the correct number of bits for the mantissa : 01001.1100000 (assume 12 bit mantissa, 4 bit exponent for this)

• Move binary point to left until it is after the sign bit – count how many moves - because that is the exponent

• 0.10011100000 and the exponent is 4• Final answer : 010011100000 0100

CP4

Sign 8 4 2 1 . .5 .25

0 1 0 0 1 . 1 1

Page 14: The Teacher CP4 Binary and all that… CP4 Revision

The TeacherCP4

Binary Exercises

1. Using 8-bit Two’s Complement system…how would these numbers be represented?

1. 4310

2. -4310

2. Using Sign and Magnitude system, how would the above numbers be represented?

3. Convert your answers to [1] into hexadecimal.

Page 15: The Teacher CP4 Binary and all that… CP4 Revision

The TeacherCP4

Binary Exercises

• [CP4 2006](i) Convert the 12 bit binary number 101111010111 to hexadecimal. [1]  

• (ii) Why is hexadecimal often used as an alternative to binary? [1]

• [CP4 2005]• In a certain computer, two's complement is used to represent

negative integers, using 8 bits.  • (i) Show how the number -710 is represented. [1]   • (ii) Showing your working, demonstrate that 1310 is the result of the

binary addition of -710 to +2010. [2]  • (b)In another computer, a sign/magnitude approach is used to

represent integers using 8 bits. Explain what is meant by the term sign/magnitude, giving a clearly labelled example [2]  

• (c)In another computer, the character '1' is stored as 00110001. The character '2' is stored as the next higher binary code (00110010) and so on. How will the character '5' be stored? [1]