Number Systems

23
Computing Theory – F453 Number Systems

description

Number Systems. Computing Theory – F453. Data Representation. Data in a computer needs to be represented in a format the computer understands. This does not necessarily mean that this format is easy for us to understand. Not easy, but not impossible! - PowerPoint PPT Presentation

Transcript of Number Systems

Page 1: Number Systems

Computing Theory – F453

Number Systems

Page 2: Number Systems

Data in a computer needs to be represented in a format the computer understands.This does not necessarily mean that this format is easy for us to understand.

Not easy, but not impossible!

A computer only understand the concept of ON and OFF.Why?

How do we translate this into something WE understand?We use a numeric representation (1s and 0s)

Data Representation

Page 3: Number Systems

If a computer can only understand ON and OFF, which is represented by 1 and 0, then which is which?

1 = ON0 = OFFThis is known as the Binary system. Because there are only 2 digits involved, it is known as Base 2.

But what does it MEAN??!

Data Representation

Page 4: Number Systems

We use the Denary Number System.This is in Base 10, because there are 10 single digits in our number system.

Why? We are surrounded by things that are divisible by ten.

Counting in tens is not a new phenomenon…Even the Egyptians did it!

Denary Numbers

Page 5: Number Systems

Yes!• The Mayans used the Vigesimal system (Base 20)• Nigerians use the Duodecimal system (Base 12)• The Babylonians used Base 60!!

So…. ‘Base’ means the number of digits available in the system.

Denary has 10 individual digits:0 1 2 3 4 5 6 7 8 9 to make the next number we have to combine two digits: 10

Are there other notations?

Page 6: Number Systems

BinaryBinary can be easily calculated from denary by using the following steps:

Let’s try the number 42.

128 64 32 16 8 4 2 1

Is 42 > 128?Is 42 > 64?Is 42 > 32?32-42 = 10

1Is 10 > 16?Is 10 > 8? 110-8 = 2Is 2 > 4?Is 2 > 2?

1

2-2 = 0

0 0 0 0 0

Page 7: Number Systems

Past paper questions are one of the best ways to help you remember the answers when it matters….

Exam Practice!

Page 8: Number Systems

Markscheme Answer:

699

Page 9: Number Systems

The Octal system uses Base 8 (denary is Base 10)Which means that Octal numbers are arranged ascending in powers of 8

So how do I get from Denary to Octal??!USE BINARY!

00101010 is our binary number 000 101 010 is split into three (from the right, adding a leading 0) 0 5 2 is the Octal 0x82+5x81+2x80 = 0 + 40 + 2 = 42

The 2, 1 & 0 powers relate to the base octal figures in the table above

Octal

Octal 7 6 5 4 3 2 1 0Binary 111 110 101 100 011 010 001 000

Page 10: Number Systems

From the example shown:

Octal numbers are creating by taking the sets of three bits from the right of a binary number and creating a leading zero

This is then converted into it’s Octal format

This can be converted from Octal to Denary by multiplying each digit by 8 to the power of the Octal unit and adding the total value together.

Relating Octal to Binary

Page 11: Number Systems

Hexadecimal is very similar to Octal in that it has a differing base equivalent to denary, you just need the table!Hex, is counted in Base 16, which means it has 16 possible digits before you get into double figures.

Where in Octal, you needed 3 binary bits to create all possible 8 digits, in Hex we need 4 binary bits.

This is half a binary byte – also known as a nibble

HexadecimalHexidecimal

Binary

0 00001 00012 00103 00114 01005 01016 01107 01118 10009 1001A 1010B 1011C 1100D 1101E 1110F 1111

Page 12: Number Systems

Now trying to convert this into Hexadecimal….

Try This:

128 64 32 16 8 4 2 11

252 – 128 = 124

124 – 64 = 60

60 – 32 = 2828 – 16 = 1212 – 8 = 44 – 4 = 0

1 1 1 1 1 0 0

Convert 252 in denary into Binary:

First split the byte into two nibbles

1248

Now, convert each of the nibbles into their Hexadecimal equivalent

1111 = F 1100 = C

So, 252 in denary, must be FC in Hexadecimal!

Page 13: Number Systems

We have already seen this in action through converting Denary into Octal and Hexadecimal.Binary Coded Decimal (BCD) is the binary equivalent of the decimal digits we use.

Think back to your first years in school where you were taught to count in units, tens, and hundreds. This was teaching you the basis of the denary system.

BCD takes each of these denary digits and changes themInto their binary equivalent….

Binary Coded Decimal

Page 14: Number Systems

Use the table below to write out the denary number 3142 in binary coded decimal.

BCD can be used to represent large denary numbers.Specifically those larger then 255. Why?

Binary Coded Decimal

Decimal Binary0 00001 00012 00103 00114 01005 01016 01107 01118 10009 1001

0011 0001 0100 0010

3 1 4 2

Page 15: Number Systems

Numbers can be represented in a format known as Two’s Complement.

Think of a car milometer – It starts at 000000.Move forward, and it becomes 000001But what if it moves back? There is no -1?!

Instead the clock goes to 999999 which represents -1 mile.

So, in Two’s complement, we look at the leading number which represents the sign : 1 being negative and 0 being positive.

But Some Numbers Are Negative!

Page 16: Number Systems

A few examples:

11111101 = -3 why? How?

Two’s complement

- 128

64 32 16 8 4 2 1

1 1 1 1 1 1 0 1

If this is a 1, we change 128 to -128

-128+64+32+16+8+4+1 .-3 .

Page 17: Number Systems

= -2

More Examples:-

12864 32 16 8 4 2 1

1 1 1 1 1 1 1 0

+ 128

64 32 16 8 4 2 1

0 1 0 0 1 0 1 0

= 74

- 128

64 32 16 8 4 2 1

1 0 1 0 1 1 1 0= 82

Page 18: Number Systems

1. Find the binary value of the equivalent decimal number first

2. Change all the 0’s to 1’s and vice versa

3. Add 1 to the result.

OR1. Starting from the right, leave all the digits alone up to and including the first ‘1’

2. Now, change all the other digits from 0 to 1 or 1 to 0

Converting Negative Denary into Binary….

Page 19: Number Systems

Examples!+

12864 32 16 8 4 2 1

0 1 0 0 1 0 1 0

= 74

- 128

64 32 16 8 4 2 1

1 0 1 1 0 1 1 0

1. Starting from the right, leave all the digits alone up to and including the first ‘1’

= -74

2. Now, change all the other digits from 0 to 1 or 1 to 0

-128+32+16+4+2= - 74!

Page 20: Number Systems

Ok. So how does a computer recognise the alphabet?

If a computer can recognise numbers through binary, then we can assign a numeric value to a letter which will allow the computer to recognise it!

A character set is a table of Alphabetical (alpha) characters showing their numeric equivalent.

There are two major character sets:ASCII – American Standard Code for Information InterchangeUNICODE – Universal Codes

Enough With The Maths!

Page 21: Number Systems

ASCII is pronounced ‘as-ski’

It is based on the Latin alphabet, that is, it was originally developed to use the English Language.

Historically ASCII was developed for telegraphic printers (think REALLY old fax machines)

UNICODE was developed later on to encompass the many different alphabets used across the globe (and now includes the dreaded Wingdings…. And even Klingon!)

ASCII / UNICODE Character Sets

Page 22: Number Systems
Page 23: Number Systems

RepresentationDenary (Base 10)Binary (Base 2)Octal (Base 8)Hexadecimal (Base 16)Binary Coded DecimalSign & MagnitudeTwo’s Compliment

Key Terms:Character SetASCIIUnicode