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

Similar documents
Floating Point. The World is Not Just Integers. Programming languages support numbers with fraction

COMP2611: Computer Organization. Data Representation

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

Inf2C - Computer Systems Lecture 2 Data Representation

Floating Point Arithmetic

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

COMP Overview of Tutorial #2

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

Floating-Point Data Representation and Manipulation 198:231 Introduction to Computer Organization Lecture 3

CS 101: Computer Programming and Utilization

M1 Computers and Data

Divide: Paper & Pencil

Chapter 3: Arithmetic for Computers

IEEE Standard for Floating-Point Arithmetic: 754

Module 2: Computer Arithmetic

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

Signed Multiplication Multiply the positives Negate result if signs of operand are different

Number Systems CHAPTER Positional Number Systems

Number System. Introduction. Decimal Numbers

Numeric Encodings Prof. James L. Frankel Harvard University

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

Number Systems. Both numbers are positive

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

Floating-point Arithmetic. where you sum up the integer to the left of the decimal point and the fraction to the right.

Chapter Three. Arithmetic

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

Introduction to Computers and Programming. Numeric Values

Organisasi Sistem Komputer

Computer Architecture Chapter 3. Fall 2005 Department of Computer Science Kent State University

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

CO212 Lecture 10: Arithmetic & Logical Unit

Number representations

Numerical Representations On The Computer: Negative And Rational Numbers

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

MACHINE LEVEL REPRESENTATION OF DATA

Floating point. Today! IEEE Floating Point Standard! Rounding! Floating Point Operations! Mathematical properties. Next time. !

Numerical Representations On The Computer: Negative And Rational Numbers

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

Number Systems and Computer Arithmetic

Integers and Floating Point

Floating Point Numbers. Lecture 9 CAP

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

Floating Point (with contributions from Dr. Bin Ren, William & Mary Computer Science)

1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM

ECE232: Hardware Organization and Design

IEEE-754 floating-point

COSC 243. Data Representation 3. Lecture 3 - Data Representation 3 1. COSC 243 (Computer Architecture)

CHW 261: Logic Design

Chapter 4: Data Representations

SIGNED AND UNSIGNED SYSTEMS

C NUMERIC FORMATS. Overview. IEEE Single-Precision Floating-point Data Format. Figure C-0. Table C-0. Listing C-0.

Computer Arithmetic Ch 8

Computer Arithmetic Ch 8

CMPSCI 145 MIDTERM #1 Solution Key. SPRING 2017 March 3, 2017 Professor William T. Verts

3.5 Floating Point: Overview

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

CS61c Midterm Review (fa06) Number representation and Floating points From your friendly reader

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

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

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

Foundations of Computer Systems

EE 109 Unit 19. IEEE 754 Floating Point Representation Floating Point Arithmetic

Chapter 10 Binary Arithmetics

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

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

Computer Organisation CS303

Floating Point Numbers

Floating Point Numbers

Chapter 4. Operations on Data

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

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

Number Representations

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

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

CS101 Introduction to computing Floating Point Numbers

Data Representation 1

Scientific Computing. Error Analysis

Floating Point Numbers

Data Representation Floating Point

Kinds Of Data CHAPTER 3 DATA REPRESENTATION. Numbers Are Different! Positional Number Systems. Text. Numbers. Other

World Inside a Computer is Binary

unused unused unused unused unused unused

Numerical computing. How computers store real numbers and the problems that result

Operations On Data CHAPTER 4. (Solutions to Odd-Numbered Problems) Review Questions

Computer Architecture and IC Design Lab. Chapter 3 Part 2 Arithmetic for Computers Floating Point

Chapter 2 Float Point Arithmetic. Real Numbers in Decimal Notation. Real Numbers in Decimal Notation

Floating Point January 24, 2008

Chapter 2 Data Representations

±M R ±E, S M CHARACTERISTIC MANTISSA 1 k j

Signed umbers. Sign/Magnitude otation

Floating Point Puzzles. Lecture 3B Floating Point. IEEE Floating Point. Fractional Binary Numbers. Topics. IEEE Standard 754

CS 261 Fall Floating-Point Numbers. Mike Lam, Professor.

The ALU consists of combinational logic. Processes all data in the CPU. ALL von Neuman machines have an ALU loop.

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

CS101 Lecture 04: Binary Arithmetic

EE 109 Unit 6 Binary Arithmetic

Data Representations & Arithmetic Operations

Digital Fundamentals

Chapter 2 Bits, Data Types, and Operations

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

Transcription:

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

Number representations? What for? Recall: computer works with binary numbers Groups of zeroes and ones 8 bits (byte, 16 bits (2 bytes,, 64 bits (8 bytes,... Number of bits determines range of numbers If a number does not fit overflow! So far we have used unsigned integer numbers Natural numbers with zero included People usually need other kinds of numbers Positive, negative, fractions,... Groups of zeroes and ones again? We can interpret bits in different ways Some interpretations more useful than others 2

Positive/negative integer numbers Things to consider Distinguishing positive/negative numbers Difficulty working with the numbers (in HW Arithmetic, negation, detecting overflow Extending/truncating fixed-size representation Sign and magnitude representation Explicit sign bit (where to put it? N bits { -(2 N-1,, -0, +0,, 2 N-1 } Biased representation Implicit sign bit (only for bias of 2 N-1-1 N bits with bias B { -B,, 0,, 2 N - 1 - B } 3

Positive/negative integer numbers One s complement representation Implicit sign bit, symmetric range Negation is flip all bits N bits { -(2 N-1,, -0, +0,, 2 N-1 } Two s complement representation Implicit sign bit, asymmetric range Negation is flip all bits, then add 1 N bits { -(2 N-1,, 0,, 2 N-1-1 } b N-1 -(2 N-1 + b N-2 2 N-2 + + b 1 2 1 + b 0 2 0 Modular arithmetic! Subtract by adding in unsigned arithmetic 4

Extending/truncating numbers General principle Ensure that interpreting the extended/truncated representation gives the same number Truncation can result in loss of information! Unsigned integers Extend with zero bits to the left, truncation trivial Sign and magnitude representation Strip sign, extend/truncate as unsigned, set sign One s and two s complement representations Extend using the value of the highest bit, truncation trivial 5

Representing fractional numbers Fixed point representation Decimal analogy: numbers 0 99 divided by 10 allow representing 0.0, 0.1, 0.2,, 9.9 In binary, the fractional part of a number is the sum of negative powers of 2 Works also with two s complement Example: 4.4 fixed-point representation Integral part: 0, 1,, 15 Fractional part: 0 0.0625,, 15 0.0625 = 0.9375 2 3 = 8 2 2 = 4 2 1 = 2 2 0 = 1 2-1 = 0.5 2-2 = 0.25 2-3 = 0.125 2-4 = 0.0625 b 7 = MSB b 6 b 5 b 4 b 3 b 2 b 1 b 0 = LSB (Imaginary fixed point 6

Decimal binary conversion Fractional part Convert separately from integral part Simple algorithm Multiply fractional part by 2 Value before decimal point provides next fraction bit, starting with MSB Strip of the fractional part and repeat until zero, or... the pattern starts repeating we have enough bits 0.678 10 =??? 2 0.678 2 = 1.356 (1 = b -1 0.356 2 = 0.712 (0 = b -2 0.712 2 = 1.424 (1 = b -3 0.424 2 = 0.848 (0 = b -4 0.848 2 = 1.696 (1 = b -5 0.696 2 = 1.392 (1 = b -6 0.392 2 = 0.784 (0 = b -7 0.784 2 = 1.568 (1 = b -8... 0.678 10 0.10101101 2 7

Approximating real numbers Floating point representation Decimal analogy: normalized scientific notation D 0, D 1 D 2...D P-1 10 E (P valid digits, 1 D 0 9 Similarly in binary B 0, B 1 B 2...B P-1 2 E (P valid bits, 1 B 0 1 In-memory representation B 0 is always 1 in this form Sign Exponent (with bias Significand (value of B 0 not stored hidden 1 SP DP Bias = 127 Bias = 1023 (-1 Sign (Exponent - Bias Significand 2 P = 24 P = 53 Half (16-bit / Single (32-bit / Double (64-bit 8

Real number IEEE floating point 1. Convert to binary fractional number Integral and fractional part, ignore sign 2. Normalize the binary representation Move binary point to get 1.ssss 2 Exp 3. Depending on the target FP representation Round significand to desired precision Convert the exponent to biased representation 4. Set the sign bit to reflect the sign 5. For in-memory representation Drop initial 1 from the significand (hidden 1 9

Speaking of memory... Programmer s perspective (logical view 1-D array of N bytes numbered 0,, N-1 Individual bytes can be read or written to A particular byte is identified by its index Index => Address Numbers occupy multiple bytes in memory Address of something = address of first byte Memory is visible to CPU CPU sends address to memory controller, requesting bytes to be read or written Memory controller uses parts of the address to determine which part of memory to access 10

How to store multi-byte numbers? Memory = array of bytes Chop up number into sequence of N bytes B N-1 (Most Signif. Byte,, B 1, B 0 (Least Signif. Byte Store N bytes at consecutive addresses in memory Addresses A, A+1, A+2,, A+(N-1 for N-byte number CPU does this when storing/loading contents of its registers to/from memory at a given address The order of bytes matters! Similar to sending bits over serial line. Big Endian = MSB first A A+1... A+(N-1 Little Endian = LSB first A A+1... A+(N-1 B N-1 B N-2... B 0 B 0 B 1... B N-1 11

Understanding a memory dump Lists contents of memory Or any other address space, e.g., storage device (hard disk, solid state drive, or a file Contents of starting address and fixed number of consecutive addresses (usually all in hexadecimal We must know the interpretation! What is stored at 0x03194A7B? Or at 0x03194A84? Address Byte at (Address + 0, (Addres + 1,, (Address + 7... 03194A78 AF BC 39 F6 D0 24 91 34 03194A80 81 C9 A3 7C 00 80 B7 C2 03194A88 E2 6C 71 EA 59 FE F5 49... 12