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

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

Chapter 4: Data Representations

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

COMP2611: Computer Organization. Data Representation

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

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

CHW 261: Logic Design

Signed Binary Numbers

M1 Computers and Data

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

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

Numeric Encodings Prof. James L. Frankel Harvard University

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

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

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

Digital Fundamentals

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

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

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

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

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

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

Topic Notes: Bits and Bytes and Numbers

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

COMP Overview of Tutorial #2

Final Labs and Tutors

Computer Organization

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

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

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

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

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

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

Chapter 2. Data Representation in Computer Systems

COMP2121: Microprocessors and Interfacing. Number Systems

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

Topic Notes: Bits and Bytes and Numbers

Data Representation 1

Introduction to Computers and Programming. Numeric Values

Binary Representations and Arithmetic

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

Arithmetic Operations

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

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.

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

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

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

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

Integer Representation

T02 Tutorial Slides for Week 2

Data Representation COE 301. Computer Organization Prof. Muhamed Mudawar

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

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

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

LING 388: Computers and Language. Lecture 5

CHAPTER 2 Data Representation in Computer Systems

Chapter 3: Arithmetic for Computers

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

CHAPTER 2 Data Representation in Computer Systems

Beginning C Programming for Engineers

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

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

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

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

Arithmetic and Bitwise Operations on Binary Data

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

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

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

Number Systems CHAPTER Positional Number Systems

Five classic components

Arithmetic and Bitwise Operations on Binary Data

Integers and Floating Point

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

Chapter 2 Bits, Data Types, and Operations

EE 109 Unit 2. Binary Representation Systems

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

Numbering systems. Dr Abu Arqoub

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

More about Binary 9/6/2016

CS 101: Computer Programming and Utilization

Number Systems and Number Representation

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

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

1.1 Information representation

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

EE292: Fundamentals of ECE

ECOM 2325 Computer Organization and Assembly Language. Instructor: Ruba A.Salamah INTRODUCTION

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

Signed umbers. Sign/Magnitude otation

Survey. Motivation 29.5 / 40 class is required

CHAPTER 1 Numerical Representation

Microcomputers. Outline. Number Systems and Digital Logic Review

Binary Codes. Dr. Mudathir A. Fagiri

Lecture 2: Number Systems

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 ( volts) and one for logic (3.3 volts). DRAM uses a single capacitor to store and a transistor to select. SRAM typically uses 6 transistors. Definition: A bit is 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 bit.

Storing Information Value Representation Value Representation Value Representation H T False True e-4 5 Use more bits for more items Three bits can represent 8 values:,,, N bits can represent 2 N values: N 8 6 32 64 Can represent 256 65,536 4,294,967,296.8446 x 9 Approximately 65 thousand (64K where K=24) 4 billion 2 billion billion

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

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

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

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 (6 hex) is different than A (4 hex) 8 (38 hex) is different than the integer 8 is 3 (hex) or 48 (decimal) 9 is 39 (hex) or 57 (decimal)

ASCII and Integer I/O Consider this program, what does it do? getc $t # get a digit add $t2, $t, $t putc $t2

ASCII and Integer I/O How to convert digits asciibiad:.word 48 # code for, 49 is, # do a syscall to get a char, move to $t sub $t2, $t, 48 # convert char for digit to num add $t3, $t2, $t2 add $t3, $t3, 48 # convert back to char putc $t3 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 integer representation

Algorithm: Character string Integer Example: For 3 5 4 Read 3 translate 3 to 3 Read 5 translate 5 to 5 integer = 3 x + 5 = 35 Read 4 translate 4 to 4 integer = 35 x + 4 = 354 Algorithm: asciibias = 48 integer = while there are more characters get character digit character asciibias integer integer x + digit

Algorithm: Integer Character string Example: For 354, figure out how many characters there are (3) For 354 div gives 3 translate 3 to 3 and print it out 354 mod gives 54 54 div gives 5, translate 5 to 5 and print it out, 54 mod gives 4 4 div gives 4 translate 4 to 4 and print it out 4 mod gives, so your done

Character String / Integer Representation Compare: mystring:.asciiz 23 mynumber:.word 23 23 is x3 2 x32 3 x33 \ x A series of four ASCII characters 23 = x7b = x7b = 7b A 32-bit 2 s complement integer

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

Integer Representation Usual answers: 2 types. Represent 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

Unsigned Integers Integer represented is binary value of bits:,, 2, Encodes only positive values and zero Range: to 2 n, for n bits Example: 4 bits, values to 5 n = 4, 2 4 is 5 [:5] = 6 = 2 4 different numbers 7 is 7 not represent able -3 not represent able Example: 32 bits = [: 4,294,967,295] 4,294,967,296 = 2 32 different numbers

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. Representation Use bit of integer to represent the sign of the integer Sign bit is msb: is +, 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- ) to 2 n- -

Signed Magnitude - Example 4 bits -2 3 + to 2 3-7 to +7 Questions: is? -3 is? +2 is? [-7,, -,, +,,+7] = 7 + + 7 = 5 < 6 = 2 4 Why? What problems does this cause?

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

One s Complement Representation To get s complement of Take +: Complement each bit: Don t add or take away any bits. Examples: This must be a negative number. To find out which, find the additive inverse! is +3 must be? Properties of s complement: Any negative number will have a in the MSB There are 2 representations for, and

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

Two s Complement Example: (+5) (-5 in s complement) + (-5 in 2 s complement) To get the additive inverse of a 2 s complement integer,. Take the s complement 2. Add Number of integers represented: With 4 bits: [-8,,-,,+,,+7] = 8++7=6=2 4 numbers With 32 bits: [-23,,-,,+,,(23-)] = 23++(23-)=232 [-2474836448,,-,,+,,247483647] ~ ±2B

A Little Bit on Adding Simple way of adding : Start at LSB, for each bit (working right to left) While the bit is a, change it to a. When a is encountered, change it to a and stop. Can combine with bit inversion to form 2 s complement. More generally, it s just like decimal!! + = + = + = 2, which is in binary, sum is, carry is. + + = 3, sum is, carry is. x +y + sum

A Little Bit on Adding Carry out Sum B A Carry in

Biased Representation 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 (8) (Excess 8) true value to be represented 3 Add in the bias +8 Unsigned value The bit pattern of 3 in biased-8 representation will be Suppose we were given a biased-8 representation as Unsigned 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?

Biased Representation 25 in excess : 52,excess27 is: 2,excess3 is: 2,excess3 is: Where is the sign bit in excess notation? Used in floating-point exponents n-bit biased notation must specify the bias Choosing a bias: To get a ~ equal distribution of values above and below, the bias is usually 2 n- or 2 n-.

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 Unsigned: xxxxx xxxxx Copy the original integer into the LSBs, and put s elsewhere Sign/magnitude: sxxxxx sxxxxx Copy the original integer s magnitude into the LSBs Put the original sign into the MSB, put s elsewhere

Sign Extension s and 2 s complement: Sign Extension sxxxxx sssxxxxx Copy the original integer into the LSBs Take the MSB of the original and copy it elsewhere In 2 s complement, the MSB (sign bit) is the 2 n- place. It says subtract 2 n- from b n-2 b. Sign extending one bit Adds a 2 n place Changes the old sign bit to a +2 n- place -2 n + 2 n- = -2 n-, so the number stays the same

Sign Extension -2 in 8-bit 2 s complement: It s additive inverse is: