CSCI 198: Lecture 4: Data Representation

Slides:



Advertisements
Similar presentations
Representing Information as Bit Patterns Lecture 4 CSCI 1405, CSCI 1301 Introduction to Computer Science Fall 2009.
Advertisements

Data Representation in Computers
Data Representation (in computer system) Computer Fundamental CIM2460 Bavy LI.
CHARACTERS Data Representation. Using binary to represent characters Computers can only process binary numbers (1’s and 0’s) so a system was developed.
Bits, Bytes, KiloBytes, MegaBytes, GigaBytes & TeraBytes.
Simple Data Type Representation and conversion of numbers
CSCI 125 & 161 Lecture 2 Martin van Bommel. Hardware vs Software Hardware - physical components you can see and touch –e.g. processor, keyboard, disk.
Computers Organization & Assembly Language
Data Representation S2. This unit covers how the computer represents- Numbers Text Graphics Control.
Binary Arithmetic & Data representation
Computer Structure & Architecture 7c - Data Representation.
EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
Number Systems Spring Semester 2013Programming and Data Structure1.
What is a computer? A computer is a device that:
The Teacher CP4 Binary and all that… CP4 Revision.
1 Lecture 2  Complement  Floating Point Number  Character Encoding.
The Teacher CP4 Binary and all that… CP4 Revision.
1 Data Representation Characters, Integers and Real Numbers Binary Number System Octal Number System Hexadecimal Number System Powered by DeSiaMore.
Representing Characters in a computer Pressing a key on the computer a code is generated that the computer can convert into a symbol for displaying or.
Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, Signed Integers The highest bit indicates the sign. 1 = negative, 0 = positive.
Digital Fundamentals Tenth Edition Floyd Chapter 2 © 2008 Pearson Education.
Data Representation.
CS 160 Lecture 4 Martin van Bommel. Overflow In 16-bit two’s complement, what happens if we add =
Chapter 1 Representing Data in a Computer. 1.1 Binary and Hexadecimal Numbers.
Nguyen Le CS147.  2.4 Signed Integer Representation  – Signed Magnitude  – Complement Systems  – Unsigned Versus Signed Numbers.
CS 125 Lecture 3 Martin van Bommel. Overflow In 16-bit two’s complement, what happens if we add =
The Hexadecimal System is base 16. It is a shorthand method for representing the 8-bit bytes that are stored in the computer system. This system was chosen.
 Computers are 2-state devices › Pulse – No pulse › On – Off  Represented by › 1 – 0  BINARY.
11001 / 101, / ) Perform subtraction on the given unsigned binary numbers using the 2's complement of the subtrahend. Where the result.
1.4 Representation of data in computer systems Character.
Floating Point Numbers
Nat 4/5 Computing Science Data Representation Lesson 3: Storing Text
Nat 4/5 Computing Science Data Representation Lesson 3: Storing Text
Some basic concepts underlying computer archi­tecture
Data Representation COE 308 Computer Architecture
Computer Science 210 Computer Organization
Programming and Data Structure
Data Representation ICS 233
Lec 3: Data Representation
Binary 1 Basic conversions.
Data Representation.
Number Representation
3.1 Denary, Binary and Hexadecimal Number Systems
Data Representation Binary Numbers Binary Addition
11001 / 101 , / ) Perform subtraction on the given unsigned binary numbers using the 2's complement of the subtrahend. Where the.
CSCI 161: Lecture 4: Data Representation
CSE 102 Introduction to Computer Engineering
Data Encoding Characters.
University of Gujrat Department of Computer Science
CS1010 Programming Methodology
Data Representation COE 301 Computer Organization
Computer Science 210 Computer Organization
Information Representation
COMS 161 Introduction to Computing
C1 Number systems.
COMS 161 Introduction to Computing
Plan Attendance Files Posted on Campus Cruiser Homework Reminder
Storing Negative Integers
How Computers Store Data
Chapter 3 DataStorage Foundations of Computer Science ã Cengage Learning.
2’s Complement form 1’s complement form 2’s complement form
Data Representation ICS 233
Learning Intention I will learn how computers store text.
ECE 331 – Digital System Design
Beyond Base 10: Non-decimal Based Number Systems
Networks & I/O Devices.
Data Representation COE 308 Computer Architecture
Presentation transcript:

CSCI 198: Lecture 4: Data Representation

Running the program Wrong result! What happen? A run: please input two numbers: num1 = 2 num2 = 3 the sum is 5 Another run: num1 = 450 num2 = 300 the sum is 750 One more time please input two numbers: num1 = 2000000034 num2 = 9999999999 the sum is -147483615 Wrong result! What happen?

Data Representation

Decimal Number Systems Base 10 Digits - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 e.g. 34210 = = 3 x 102 + 4 x 101 + 2 x100 = 3 x 100 + 4 x 10 + 2 x 1 = 300 + 40 + 2

Binary Number System Base 2 Digits 0, 1 e.g. 1102 = = 1 x 22 + 1 x 21 + 0 x 20 = 1 x 4 + 1 x 2 + 0 x 1 = 4 + 2 + 0 = 6

Counting in Binary Decimal Binary 0 0 1 1 2 10 3 11 4 100 5 101 6 110 0 0 1 1 2 10 3 11 4 100 5 101 6 110 7 111 Decimal Binary 8 1000 9 1001 10 1010 11 1011 12 1100 13 1101 14 1110 15 1111

Addition 0+ 0 1 + 0 0 + 1 1 + 1 1101 + 0111

How many symbol can N digit represent? 3 digit allows representing 8 numbers (symbols): 0-7 4 16: 0 – 15 N 2N

16-bit Memory Word To store number 6, use 0000000000000110 Value 0 is 0000000000000000 Largest value is 1111111111111111 = 65,535 = 216 − 1 32-bit word gives largest value > 4 billion

Number of bits How many states can be represented with 1 bits, 2 bits, 3 bits, 8 bits …. To represent N states, how many bits are needed: log2N

Character Representation 1 byte = 8 bits = 1 character? 256 possible codes with 8 bits Assign a character to each code Common assignment ASCII - American Standard Code for Information Interchange – defines first 128

ASCII Code Code Value Letter 0 Null character 1 - 31 Special Control Characters 10 \n = New line 32 Space 33-47, 58-64, 91-96 Punctuation 48 - 57 0 - 9 65 - 90 A - Z 97 - 122 a - z

Interesting ASCII Choice? Digits 0 through 9 seem strange? Digit Dec Hex 0 48 30 1 49 31 … … … 9 57 39

Unicode International language coding standard Superset of ASCII Various codes defined to use upper 128 bits for symbols in other languages

Storing Negative Values Two’s complement!

Two’s Complement Two’s complement if positive, use binary if negative, complement bits and add one e.g. −53 magnitude 00110101 complement 11001010 add 1 11001011

Overflow In 16-bit two’s complement, what happens if we add 32767 0111111111111111 + 1 0000000000000001 -------- ------------------------ −32,768 1000000000000000

Large and Small Numbers On 9-digit calculator, 999999999 + 1 = 1.0 E 9 In binary, 11111111 + 1 = 1.0 x 28 Small numbers, 0.510 = ½10 = 0.12 = 1.0 x 2-1

Real Numbers in Binary 0.11011 x 24 = 1101.1 = 8 + 4 + 1 + 0.5 = 13.5 In 16-bit word, 0 1 1 0 1 1 0 0 0 0 0 0 0 1 0 0 sign mantissa exponent

Converting Decimal to Binary Repeatedly divide by 2, recording remainders in reverse order e.g. 53 / 2 = 26 R 1 26 / 2 = 13 R 0 13 / 2 = 6 R 1 6 / 2 = 3 R 0 3 / 2 = 1 R 1 1 / 2 = 0 R 1 giving 110101

Converting Binary to Decimal Repeatedly multiply by 2 and add next bit e.g. 1101 = 1* 22 + 1*22 + 0 *21 + 1*20