DRAM uses a single capacitor to store and a transistor to select. SRAM typically uses 6 transistors.

Similar documents
Data Representation. DRAM uses a single capacitor to store and a transistor to select. SRAM typically uses 6 transistors.

Chapter 4: Data Representations

COMP2611: Computer Organization. Data Representation

MACHINE LEVEL REPRESENTATION OF DATA

Inf2C - Computer Systems Lecture 2 Data Representation

IT 1204 Section 2.0. Data Representation and Arithmetic. 2009, University of Colombo School of Computing 1

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

UNIT 7A Data Representation: Numbers and Text. Digital Data

Signed Binary Numbers

M1 Computers and Data

Number Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Bits and Bytes and Numbers

BINARY SYSTEM. Binary system is used in digital systems because it is:

COMP Overview of Tutorial #2

Numeric Encodings Prof. James L. Frankel Harvard University

CHW 261: Logic Design

9/3/2015. Data Representation II. 2.4 Signed Integer Representation. 2.4 Signed Integer Representation

Number Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column

Integers. N = sum (b i * 2 i ) where b i = 0 or 1. This is called unsigned binary representation. i = 31. i = 0

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

l l l l l l l Base 2; each digit is 0 or 1 l Each bit in place i has value 2 i l Binary representation is used in computers

Final Labs and Tutors

Digital Fundamentals

Topic Notes: Bits and Bytes and Numbers

The type of all data used in a C++ program must be specified

The type of all data used in a C (or C++) program must be specified

Number Systems Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur Number Representation

Chapter 2. Positional number systems. 2.1 Signed number representations Signed magnitude

Thus needs to be a consistent method of representing negative numbers in binary computer arithmetic operations.

Representing Information. Bit Juggling. - Representing information using bits - Number representations. - Some other bits - Chapters 1 and 2.3,2.

CPS 104 Computer Organization and Programming Lecture-2 : Data representations,

COMP2121: Microprocessors and Interfacing. Number Systems

Chapter 2. Data Representation in Computer Systems

Topic Notes: Bits and Bytes and Numbers

Computer Organization

Question 4: a. We want to store a binary encoding of the 150 original Pokemon. How many bits do we need to use?

Chapter 10 Binary Arithmetics

SISTEMI EMBEDDED. Basic Concepts about Computers. Federico Baronti Last version:

A complement number system is used to represent positive and negative integers. A complement number system is based on a fixed length representation

SIGNED AND UNSIGNED SYSTEMS

Computer (Literacy) Skills. Number representations and memory. Lubomír Bulej KDSS MFF UK

Binary Addition. Add the binary numbers and and show the equivalent decimal addition.

Digital Logic. The Binary System is a way of writing numbers using only the digits 0 and 1. This is the method used by the (digital) computer.

Announcement. (CSC-3501) Lecture 3 (22 Jan 2008) Today, 1 st homework will be uploaded at our class website. Seung-Jong Park (Jay)

Homework 1 graded and returned in class today. Solutions posted online. Request regrades by next class period. Question 10 treated as extra credit

Goals for this Week. CSC 2400: Computer Systems. Bits, Bytes and Data Types. Binary number system. Finite representations of binary integers

Data Representation 1

Introduction to Computers and Programming. Numeric Values

Recap from Last Time. CSE 2021: Computer Organization. It s All about Numbers! 5/12/2011. Text Pictures Video clips Audio

Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2

Basic Definition INTEGER DATA. Unsigned Binary and Binary-Coded Decimal. BCD: Binary-Coded Decimal

Binary Representations and Arithmetic

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two Solutions 26 February 2014

Semester Transition Point. EE 109 Unit 11 Binary Arithmetic. Binary Arithmetic ARITHMETIC

a- As a special case, if there is only one symbol, no bits are required to specify it.

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

EE 109 Unit 2. Analog vs. Digital. Analog vs. Digital. Binary Representation Systems ANALOG VS. DIGITAL

Lesson #1. Computer Systems and Program Development. 1. Computer Systems and Program Development - Copyright Denis Hamelin - Ryerson University

Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as:

LING 388: Computers and Language. Lecture 5

EE 109 Unit 2. Binary Representation Systems

Under the Hood: Data Representation. Computer Science 104 Lecture 2

CHAPTER 2 Data Representation in Computer Systems

Number Systems and Binary Arithmetic. Quantitative Analysis II Professor Bob Orr

Integer Representation

Arithmetic and Bitwise Operations on Binary Data

Integers and Floating Point

Data Representation COE 301. Computer Organization Prof. Muhamed Mudawar

Arithmetic and Bitwise Operations on Binary Data

Assembly Language for Intel-Based Computers, 4 th Edition. Chapter 1: Basic Concepts. Chapter Overview. Welcome to Assembly Language

Numbering systems. Dr Abu Arqoub

Digital Arithmetic. Digital Arithmetic: Operations and Circuits Dr. Farahmand

Princeton University Computer Science 217: Introduction to Programming Systems. Goals of this Lecture. Number Systems and Number Representation

CS 101: Computer Programming and Utilization

Groups of two-state devices are used to represent data in a computer. In general, we say the states are either: high/low, on/off, 1/0,...

CHAPTER 2 Data Representation in Computer Systems

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

2. MACHINE REPRESENTATION OF TYPICAL ARITHMETIC DATA FORMATS (NATURAL AND INTEGER NUMBERS).

Number Systems & Encoding

Beginning C Programming for Engineers

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

Number Systems and Number Representation

1.1 Information representation

Chapter 4: Computer Codes. In this chapter you will learn about:

Arithmetic and Logical Operations

CS 31: Introduction to Computer Systems. 03: Binary Arithmetic January 29

Number Systems CHAPTER Positional Number Systems

Five classic components

Survey. Motivation 29.5 / 40 class is required

Microcomputers. Outline. Number Systems and Digital Logic Review

CS 261 Fall Mike Lam, Professor Integer Encodings

T02 Tutorial Slides for Week 2

Chapter 2 Bits, Data Types, and Operations

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

More about Binary 9/6/2016

Chapter 3: Number Systems and Codes. Textbook: Petruzella, Frank D., Programmable Logic Controllers. McGraw Hill Companies Inc.

Representing numbers on the computer. Computer memory/processors consist of items that exist in one of two possible states (binary states).

Chapter 03: Computer Arithmetic. Lesson 09: Arithmetic using floating point numbers

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers

EE292: Fundamentals of ECE

Transcription:

Data Representation

Data Representation Goal: Store numbers, characters, sets, database records in the computer. What we got: Circuit that stores 2 voltages, one for logic 0 (0 volts) and one for logic 1 (ex: 3.3 volts). DRAM uses a single capacitor to store and a transistor to select. SRAM typically uses 6 transistors. 2

Bit Definition: A unit of information. It is the amount of information needed to specify one of two equally likely choices. Example: Flipping a coin has 2 possible outcomes, heads or tails. The amount of info needed to specify the outcome is 1 bit. 3

Storing Information Value Representation H T 0 1 Value Representation False True 0 1 Value Representation 1e-4 5 Use more bits for more items Three bits can represent 8 things: 000,001,,111 N bits can represent 2 N things N bits Can represent Which is approximately 8 256 256 16 65,536 65 thousand (64K where K=1024) 32 4,294,967,296 4 billion 64 1.8446 x10 19 20 billion billion 0 1 4

Storing Information Most computers today use: Type # of bits Name for storage unit Character 8-16 byte (ASCII) 16b Unicode (Java) Integers 32-64 word (sometimes 8 or 16 bits) Reals 32-64 word or double word 5

Character Representation Memory location for a character usually contains 8 bits: 00000000 to 11111111 (binary) 0x00 to 0xff (hexadecimal) Which characters? A, B, C,, Z, a, b, c,, z, 0, 1, 2,,9 Punctuation (,:{ ) Special (\n \O ) Which bit patterns for which characters? Want a standard!!! Want a standard to help sort strings of characters. 6

Character Representation ASCII (American Standard Code for Information Interchange) Defines what character is represented by each sequence of bits. Examples: 0100 0001 is 0x41 (hex) or 65 (decimal). It represents A. 0100 0010 is 0x42 (hex) or 66 (decimal). It represents B. Different bit patterns are used for each different character that needs to be represented. 7

ASCII Properties ASCII has some nice properties. If the bit patterns are compared, (pretending they represent integers), then A < B 65 < 66 This is good because it helps with sorting things into alphabetical order. But : a (61 hex) is different than A (41 hex) 8 (38 hex) is different than the integer 8 0 is 30 (hex) or 48 (decimal) 9 is 39 (hex) or 57 (decimal) 8

ASCII and Integer I/O Consider this program, what does it do if I enter a character from 0 to 9? GETC ; get a character ADD R0, R0, R0 ; add char to itself OUT ; print character 9

How to convert digits Need to take the bias out. ; Got character in R0, make into number LD R1, neg48 Sub ; R2=R0-R1, convert char to number ADD R3, R2, R2 LD R1, pos48 ADD R0, R3, R1 ; convert back to character OUT The subtract takes the bias out of the char representation. The add puts the bias back in. This will only work right if the result is a single digit. Needed is an algorithm for translating character strings to and from integer representation 10

Character string -> Integer Example: For 3 5 4 Read 3 translate 3 to 3 Read 5 translate 5 to 5 integer = 3 x 10 + 5 = 35 Read 4 translate 4 to 4 integer = 35 x 10 + 4 = 354 11

Pseudo code for string to integer algorithm asciibias = 48 integer = 0 while there are more characters get character digit character asciibias integer integer x 10 + digit 12

Integer -> Character string Back to the 354 example: For 354, figure out how many characters there are For 354 div 100 gives 3 translate 3 to 3 and print it out 354 mod 100 gives 54 54 div 10 gives 5, translate 5 to 5 and print it out, 54 mod 10 gives 4 4 div 1 gives 4 translate 4 to 4 and print it out 4 mod 1 gives 0, so your done 13

Character String / Integer Representation Compare these two data declarations mystring.stringz 123 mynumber.fill 123 14

Character String / Integer Representation The string 123 is: 1 =0x31 =0011 0001 2 =0x32 =0011 0010 3 =0x33 =0011 0011 \0 =0x00 =0000 0000 Which looks like this in memory: 0011 0001 0011 0010 0011 0011 0000 0000 Basically a series of four ASCII characters 15

Character String / Integer Representation The integer 123 is a number 123 = 0x7b = 0x007b Which looks like this in memory: 0000 0000 0111 1011 This is a 16-bit, 2 s complement representation 16

Integer Representation Assume our representation has a fixed number of bits n (e.g. 32 bits). o Which 4 billion integers do we want? o There are an infinite number of integers less than zero and an infinite number greater than zero. o What bit patterns should we select to represent each integer AND where the representation: o Does not effect the result of calculation o Does dramatically affect the ease of calculation o Convert to/from human-readable representation as needed. 17

Integer Representation Usual answers: 1. Represent 0 and consecutive positive integers Unsigned integers 2. Represent positive and negative integers Signed magnitude One s complement Two s complement Biased Unsigned and two s complement the most common 18

Unsigned Integers Integer represented is binary value of bits: 0000 -> 0, 0001 -> 1, 0010 -> 2, Encodes only positive values and zero Range: 0 to 2 n 1, for n bits 19

Unsigned Integers If we have 4 bit numbers: To find range make n = 4. Thus 2 4 1 is 15 Thus the values possible are 0 to 15 [0:15] = 16 different numbers 7 would be 0111 17 not represent able -3 not represent able For 32 bits: Range is 0 to 2 32-1 = [0: 4,294,967,295] Which is 4,294,967,296 different numbers 20

Signed Magnitude Integers A human readable way of getting both positive and negative integers. Not well suited to hardware implementation. But used with floating point. 21

Signed Magnitude Integers Representation: Use 1 bit of integer to represent the sign of the integer Sign bit is msb: 0 is +, 1 is Rest of the integer is a magnitude, with same encoding as unsigned integers. To get the additive inverse of a number, just flip (invert, complement) the sign bit. Range: -(2 n-1 1) to 2 n-1-1 22

Signed Magnitude - Example If 4 bits then range is: -2 3 + 1 to 2 3 1 which is -7 to +7 Questions: 0101 is? -3 is? +12 is? [-7,, -1, 0, +1,,+7] = 7 + 1 + 7 = 15 < 16 = 2 4 Why? What problems does this cause? 23

One s Complement Historically important (in other words, not used today!!!) Early computers built by Semour Cray (while at CDC) were based on 1 s complement integers. Positive integers use the same representation as unsigned. 0000 is 0 0111 is 7, etc Negation is done by taking a bitwise complement of the positive representation. Complement = Invert = Not = Flip = {0 -> 1, 1 -> 0} A logical operation done on a single bit Top bit is sign bit 24

One s Complement Representation To get 1 s complement of 1 Take +1: 0001 Complement each bit: 1110 Don t add or take away any bits. Another example: 1100 This must be a negative number. To find out which, find the inverse! 0011 is +3 1100 in 1 s Complement must be? Properties of 1 s complement: Any negative number will have a 1 in the MSB There are 2 representations for 0, 0000 and 1111 25

Two s Complement Variation on 1 s complement that does not have 2 representations for 0. This makes the hardware that does arithmetic simpler and faster than the other representations. The negative values are all slid by one, eliminating the 0 case. How to get 2 s complement representation: Positive: just as if unsigned binary Negative: Take the positive value Take the 1 s complement of it Add 1 26

Two s Complement Example, what is -5 in 2SC? 1. What is 5? 0101 2. Invert all the bits: 1010 (basically find the 1SC) 3. Add one: 1010 + 1 = 1011 which is -5 in 2SC To get the additive inverse of a 2 s complement integer 1. Take the 1 s complement 2. Add 1 27

Two s Complement Number of integers represent able is -2 n-1 to 2 n-1-1 So if 4 bits: [-8,,-1,0,+1,,+7] = 8 + 1 + 7 = 16 = 2 4 numbers With 32 bits: [-2 31,,-1,0,+1,,(2 31-1)] = 2 31 +1 + (2 31-1) = 2 32 numbers [-21474836448,,-1,0,+1,,2147483647] ~ ±2B 28

A Little Bit on Adding Simple way of adding 1: Start at LSB, for each bit (working right to left) While the bit is a 1, change it to a 0. When a 0 is encountered, change it to a 1 and stop. Can combine with bit inversion to form 2 s complement. 29

A Little Bit on Adding More generally, it s just like decimal!! 0 + 0 = 0 1 + 0 = 1 1 + 1 = 2, which is 10 in binary, sum is 0, carry is 1. 1 + 1 + 1 = 3, sum is 1, carry is 1. x 0011 +y +0001 sum 0100 30

A Little Bit on Adding Carry in A B Sum Carry out 0 0 0 0 0 0 0 1 1 0 0 1 0 1 0 0 1 1 0 1 1 0 0 1 0 1 0 1 0 1 1 1 0 0 1 1 1 1 1 1 31

Biased An integer representation that skews the bit patterns so as to look just like unsigned but actually represent negative numbers. Example: 4-bit, with BIAS of 2 3 (or called Excess 8) True value to be represented 3 Add in the bias +8 Unsigned value 11 The bit pattern of 3 in biased-8 representation will be 1011 32

Biased Representation Suppose we were given a biased-8 representation, 0110, to find what the number represented was: Unsigned 0110 represents 6 Subtract out the bias -8 True value represented -2 Operations on the biased numbers can be unsigned arithmetic but represent both positive and negative values How do you add two biased numbers? Subtract? 33

Biased Representation Exercises 25 10 in excess 100 is: 52 10,excess127 is: 101101 2,excess31 is: 1101 2,excess31 is: 34

Biased Representation Where is the sign bit in excess notation? Bias notation used in floating-point exponents. Choosing a bias: To get an ~ equal distribution of values above and below 0, the bias is usually 2 n-1 or 2 n-1 1. Range of bias numbers? Depends on bias, but contains 2 n different numbers. 35

Sign Extension How to change a number with a smaller number of bits into the same number (same representation) with a larger number of bits? This must be done frequently by arithmetic units 36

Sign Extension - unsigned Unsigned representation: Copy the original integer into the LSBs, and put 0 s elsewhere. Thus for 5 bits to 8 bits: xxxxx -> 000xxxxx 37

Sign Extension signed magnitude Signed magnitude: Copy the original integer s magnitude into the LSBs & put the original sign into the MSB, put 0 s elsewhere. Thus for 6 bits to 8 bits sxxxxx -> s00xxxxx 38

Sign Extension 1SC and 2SC 1 s and 2 s complement: 1. Copy the original n-1 bits into the LSBs 2. Take the MSB of the original and copy it elsewhere Thus for 6 bits to 8 bits: sxxxxx sssxxxxx 39

Sign Extension 2SC To make this less clear In 2 s complement, the MSB (sign bit) is the 2 n-1 place. It says subtract 2 n-1 from b n-2 b 0. Sign extending one bit Adds a 2 n place Changes the old sign bit to a +2 n-1 place -2 n + 2 n-1 = -2 n-1, so the number stays the same 40

Sign Extension What is -12 in 8-bit 2 s complement form 41