1.1 data representation

32
12/06/22 12/06/22 1 1.1 Data Representation ASCII, Binary <-> Denary Conversion, Integer & Boolean data types

Upload: ivan-russell

Post on 03-Jan-2016

43 views

Category:

Documents


0 download

DESCRIPTION

1.1 Data Representation. ASCII, Binary Denary Conversion, Integer & Boolean data types. Learning Objectives:. Describe ASCII as character format data type and explain the use of this code. Describe the binary number system. Convert simple numbers between denary and binary. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: 1.1 Data Representation

20/04/2320/04/23 11

1.1 Data Representation

ASCII, Binary <-> Denary Conversion, Integer & Boolean

data types

Page 2: 1.1 Data Representation

2220/04/2320/04/23

Learning Objectives:Learning Objectives:

Describe ASCII as character format data type and explain the use of this code.

Describe the binary number system.

Convert simple numbers between denary and binary.

Page 3: 1.1 Data Representation

3320/04/2320/04/23

The Binary System

Computers store information (data of all types – numbers, characters, sound, pictures, …) in Binary format i.e. base 2. i.e. 0 or 1i.e. 0 or 1

Used because computers can only store Used because computers can only store and understand 2 states:and understand 2 states: i.e. whether a circuit has current flowing or not i.e. whether a circuit has current flowing or not

/ circuit is closed or open / voltage is high or / circuit is closed or open / voltage is high or low.low.

1 0

Page 4: 1.1 Data Representation

4420/04/2320/04/23

Bits and BytesBits and Bytes

A binary digit (1 or 0) is known as a ‘A binary digit (1 or 0) is known as a ‘bitbit’, short ’, short for for BIBInary diginary digiTT..In modern computers bits are grouped in 8 bit In modern computers bits are grouped in 8 bit bytesbytes..A A Nibble is 4 bits (half a byte).A Word is the number of bits that the CPU can process simultaneously.

Determines the speed of the computer.Determines the speed of the computer. Processors can have 8-, 16-, 32-(standard) or 64-Processors can have 8-, 16-, 32-(standard) or 64-

(fast) bit word sizes (or more).(fast) bit word sizes (or more).

Page 5: 1.1 Data Representation

5520/04/2320/04/23

Character set Character set

The symbols that a computer (software) The symbols that a computer (software) can recognise which are represented by can recognise which are represented by binary codes that the computer binary codes that the computer understands.understands.

Page 6: 1.1 Data Representation

6620/04/2320/04/23

Character RepresentationCharacter Representation

Over the years different computer Over the years different computer designers have used different designers have used different sets of sets of binary codesbinary codes for representing characters for representing characters in a character set.in a character set.This has led to great difficulty in This has led to great difficulty in transferring information from one computer transferring information from one computer to another.to another. i.e. which binary code represents each i.e. which binary code represents each

charactercharacter

Page 7: 1.1 Data Representation

7720/04/2320/04/23

ASCII (AASCII (American merican SStandard tandard CCode ode for for IInformation nformation IInterchange)nterchange)

Represents each character in a standard Represents each character in a standard character set as a single byte binary code.character set as a single byte binary code.The standard code form that most PCs use to The standard code form that most PCs use to allow for communication between systems. allow for communication between systems. Usually uses a 7 bit binary code so can store Usually uses a 7 bit binary code so can store 128 different characters and simple 128 different characters and simple communications protocols.communications protocols.Sufficient for all characters on a standard Sufficient for all characters on a standard keyboard plus control codes.keyboard plus control codes.

Can be extended (extended ASCII) to use 8 bits (so Can be extended (extended ASCII) to use 8 bits (so can store 256 characters) to encode Latin language can store 256 characters) to encode Latin language characters.characters.

Page 8: 1.1 Data Representation

ASCII code

The first 32 ASCII codes are used for simple communications protocols, not characters.

e.g. ACK – acknowledge and would be sent by a device to acknowledge receipt of data.

0110010 – 2 0110001 – 1 ….. 1000001 – A 1000010 – B

Note: Letters have increasing values from a-z or A-Z.

Page 9: 1.1 Data Representation

Representing Characters and Numbers

e.g. If the ‘A’ key is pressed ‘1000001’ is sent to the CPU.

If the 1 key is pressed then ‘0110001’ is sent to the CPU.

If the user wants to print ‘123’ the codes for 1, 2 & 3 are sent to the printer.

Page 10: 1.1 Data Representation

101020/04/2320/04/23

SortingSorting

Characters are compared in turn from the Characters are compared in turn from the start of each word (left side) until two start of each word (left side) until two characters are different. characters are different.

The character with the highest ASCII value The character with the highest ASCII value determines which is the second word. determines which is the second word.

If 2 words are the same when one ends If 2 words are the same when one ends then the longer word is the second word.then the longer word is the second word.

Page 11: 1.1 Data Representation

111120/04/2320/04/23

Binary Arithmetic RulesBinary Arithmetic Rules

0 + 0 = 00 + 0 = 0

0 + 1 = 10 + 1 = 1

1 + 0 = 11 + 0 = 1

1 + 1 = 0 (carry 1)1 + 1 = 0 (carry 1)

1+1+1 = 1 (carry 1)1+1+1 = 1 (carry 1)

Page 12: 1.1 Data Representation

121220/04/2320/04/23

ArithmeticArithmetic

ASCII coding is fine for input and output but ASCII coding is fine for input and output but useless for arithmetic:useless for arithmetic: 2 2 0110010 0110010 -1-1 -- 0110001 0110001 11 0000000 i.e. not 1 0000000 i.e. not 1

There is no easy way to perform calculations on There is no easy way to perform calculations on the numbers stored in this way.the numbers stored in this way.

Numbers which are to be used in calculations Numbers which are to be used in calculations are therefore held in binary format.are therefore held in binary format.

Page 13: 1.1 Data Representation

131320/04/2320/04/23

Decimal or Denary systemDecimal or Denary system

134 = 100 + 30 + 4134 = 100 + 30 + 4

Each column is worth 10X as much Each column is worth 10X as much as the last i.e. base 10 (10 fingers!).as the last i.e. base 10 (10 fingers!).

100100 1010 11

11 33 44

Page 14: 1.1 Data Representation

141420/04/2320/04/23

Binary systemBinary system134 = 128 + 4 + 2134 = 128 + 4 + 2

Each column is worth 2X as much as the last Each column is worth 2X as much as the last i.e. base 2.i.e. base 2.

128128 6464 3232 1616 88 44 22 11

11 00 00 00 00 11 11 00

Most Significant Bit(MIB)

Most Significant Bit(MIB)

Least Significant Bit (LIB)

Least Significant Bit (LIB)

Increasing Bit StatusIncreasing Bit Status

Page 15: 1.1 Data Representation

151520/04/2320/04/23

Binary – Decimal Spreadsheet Binary – Decimal Spreadsheet Converter 1Converter 1

Try using it to ‘play’ with binary numbers.Try using it to ‘play’ with binary numbers. https://4565e4f1bb6fcb191b6a80b2e8cd1502a3f5fc3b.googledrive.com/

host/0BxvAvCIUrln7bjJWaDAwZ0lBVFU/as/1%20Programming/1.1%20Data%20Representation/Binary-Decimal%20converter.xls

Page 16: 1.1 Data Representation

Denary -> Binary e.g. 117Denary -> Binary e.g. 1171.1. Always use the column headings for a byte (8 bits).Always use the column headings for a byte (8 bits).2.2. 117 < 128 so put a 0 and repeat.117 < 128 so put a 0 and repeat.

128128 6464 3232 1616 88 44 22 11

00

3.3. 117 > 64 so put a 1.117 > 64 so put a 1.128128 6464 3232 1616 88 44 22 11

00 11

4.4. 117 - 64 = 53 , 53 > 32, so put a 1.117 - 64 = 53 , 53 > 32, so put a 1.128128 6464 3232 1616 88 44 22 11

00 11 11 11 00 11 00 11

5.5. 53 - 32 = 21 , 21 > 16, so put a 1.53 - 32 = 21 , 21 > 16, so put a 1.6.6. Continue this until:Continue this until:

128128 6464 3232 1616 88 44 22 11

00 11 11 11 00 11 00 11

Page 17: 1.1 Data Representation

BinaryBinary -> Denary e.g. -> Denary e.g. 1011011010110110

128128 6464 3232 1616 88 44 22 11

11 00 11 11 00 11 11 00

So 10110110 = 128 + 32 + 16 + 4 + 2 So 10110110 = 128 + 32 + 16 + 4 + 2

= 182 = 182 (denary)(denary)

Put the column headings above the binary Put the column headings above the binary number and add up all the columns with a 1 in number and add up all the columns with a 1 in them. them.

Page 18: 1.1 Data Representation

181820/04/2320/04/23

QuestionsQuestions

1. Convert the following binary numbers to 1. Convert the following binary numbers to decimal.decimal. 00110011

33 01100110

66 10101010

1010 0100000101000001

6565 0100010101000101

6969

Page 19: 1.1 Data Representation

191920/04/2320/04/23

8 bit patterns8 bit patterns

Because in modern computers bits are Because in modern computers bits are grouped in 8 bit grouped in 8 bit bytes bytes numbers in binary numbers in binary format are usually written in 8 bit patterns format are usually written in 8 bit patterns even if there are unnecessary left leading even if there are unnecessary left leading 0’s.0’s. e.g. 11(binary) = 3 (decimal)e.g. 11(binary) = 3 (decimal) But you will usually find it written as But you will usually find it written as 0000001100000011

Page 20: 1.1 Data Representation

202020/04/2320/04/23

Decimal -> Binary QuestionsDecimal -> Binary Questions

2. Convert the following decimal numbers to binary:2. Convert the following decimal numbers to binary: 55

0000010100000101 77

0000011100000111 11

0000000100000001 2626

0001101000011010 6868

0100010001000100 137137

1000100110001001

Page 21: 1.1 Data Representation

212120/04/2320/04/23

Size of numberSize of number

Using only one byte to hold a number of Using only one byte to hold a number of places a restriction on the size of number places a restriction on the size of number the computer can hold. the computer can hold.

Therefore four or more consecutive bytes Therefore four or more consecutive bytes are commonly used to store numbersare commonly used to store numbers

Page 22: 1.1 Data Representation

222220/04/2320/04/23

Binary -> Decimal QuestionsBinary -> Decimal Questions

3. What is the largest decimal number that 3. What is the largest decimal number that can be held in (hint: 2^no. of bits):can be held in (hint: 2^no. of bits): 1 byte1 byte

255 (2^8 - 1)255 (2^8 - 1) 2 bytes2 bytes

65535 (2^16 - 1)65535 (2^16 - 1) 3 bytes3 bytes

16777215 (2^24 - 1)16777215 (2^24 - 1) 4 bytes4 bytes

4294967295 (2^32-1)4294967295 (2^32-1)

Page 23: 1.1 Data Representation

232320/04/2320/04/23

IntegersIntegers

Integers are whole numbers with which Integers are whole numbers with which arithmetic can be done.arithmetic can be done.

Stored by the computer as binary Stored by the computer as binary numbers using a whole number of bytes. numbers using a whole number of bytes.

It is usual to use either 2 bytes (called It is usual to use either 2 bytes (called short integers) or 4 bytes (called long short integers) or 4 bytes (called long integers), the difference being simply that integers), the difference being simply that long integers can store larger numbers. long integers can store larger numbers.

Page 24: 1.1 Data Representation

242420/04/2320/04/23

Boolean VariablesBoolean Variables

(Yes / No) or (True / False) data(Yes / No) or (True / False) data

Example uses - a particular bit in memory Example uses - a particular bit in memory can be set to show if: can be set to show if: a disk drive is connected or nota disk drive is connected or not the ‘Break’ key is pressedthe ‘Break’ key is pressed

Page 25: 1.1 Data Representation

Main Data Main Data TypesTypes

Data Data TypesTypes

Range / Fractional Real Range / Fractional Real PrecisionPrecision

Storage Requirements Storage Requirements (bytes)(bytes)

Integer (Numeric, Whole Whole numbers, numbers, no no fractionsfractions)

Byte 0 - 2550 - 255 11

Short Integer

In Access stored by 2 bytes so +/- In Access stored by 2 bytes so +/- 32,768.32,768.

In VB stored by 4 bytes so approx. In VB stored by 4 bytes so approx. +/- 2 billion+/- 2 billion

2 - 42 - 4

Long Long IntegerInteger

In Access stored by 4 bytes so In Access stored by 4 bytes so approx. +/- 2 billion.approx. +/- 2 billion.

In VB stored by 8 bytes so approx. In VB stored by 8 bytes so approx. +/– 9.2...E+18.+/– 9.2...E+18.

4 – 84 – 8

Boolean (Y/N True/False) Often Often 11 byte is reserved byte is reserved

Page 26: 1.1 Data Representation

262620/04/2320/04/23

PlenaryPlenary

What is meant by an ASCII character?What is meant by an ASCII character?

Page 27: 1.1 Data Representation

272720/04/2320/04/23

PlenaryPlenary

A member of a standard character set.A member of a standard character set.

Set of binary codes the computer Set of binary codes the computer understands.understands.

Represented in a single byte/7 or 8 bits Represented in a single byte/7 or 8 bits used per character.used per character.

Standard nature allows for Standard nature allows for communication between systems.communication between systems.

Page 28: 1.1 Data Representation

282820/04/2320/04/23

PlenaryPlenary

A member of a standard character set.A member of a standard character set.

Set of binary codes the computer Set of binary codes the computer understands.understands.

Represented in a single byte/7 or 8 bits Represented in a single byte/7 or 8 bits used per character.used per character.

Standard nature allows for Standard nature allows for communication between systems.communication between systems.

Page 29: 1.1 Data Representation

292920/04/2320/04/23

PlenaryPlenary

Convert 101 Convert 101 (denary)(denary) to binary. to binary.

Page 30: 1.1 Data Representation

303020/04/2320/04/23

PlenaryPlenary

0110010101100101

Page 31: 1.1 Data Representation

313120/04/2320/04/23

PlenaryPlenary

Convert 10011111 to denary.Convert 10011111 to denary.

Page 32: 1.1 Data Representation

323220/04/2320/04/23

PlenaryPlenary

159159