Binary Numbers Material on Data Representation can be found in Chapter 2 of Computer Architecture (Nicholas Carter) CSIT 301 (Blum)

Slides:



Advertisements
Similar presentations
Data Representation Computer Organization &
Advertisements

Data Representation COE 205
Assembly Language and Computer Architecture Using C++ and Java
Assembly Language and Computer Architecture Using C++ and Java
Dr. Bernard Chen Ph.D. University of Central Arkansas
Simple Data Type Representation and conversion of numbers
ES 244: Digital Logic Design Chapter 1 Chapter 1: Introduction Uchechukwu Ofoegbu Temple University.
CS231 Fundamentals1 Fundamentals What kind of data do computers work with? – Deep down inside, it’s all 1s and 0s What can you do with 1s and 0s? – Boolean.
CSIT 301 (Blum)1 Recap so far (Not gotten to last time) So there were issues about the number of operands. –Recall that we have a fetch-execute cycle –
Numbering systems.
Binary Numbers. Why Binary? Maximal distinction among values  minimal corruption from noise Imagine taking the same physical attribute of a circuit,
Computers Organization & Assembly Language
CSU0014 Assembly Languages Homepage: Textbook: Kip R. Irvine, Assembly Language for Intel-Based Computers,
PHY 201 (Blum) 1 Resistors Ohm’s Law and Combinations of Resistors See Chapters 1 & 2 in Electronics: The Easy Way (Miller & Miller)
Computer System & Binary Review. Memory Model What memory is supposed to look like.
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
ECEN2102 Digital Logic Design Lecture 1 Numbers Systems Abdullah Said Alkalbani University of Buraimi.
PHY 201 (Blum)1 Binary Numbers. PHY 201 (Blum)2 Why Binary? Maximal distinction among values  minimal corruption from noise Imagine taking the same physical.
Lecture 4 Last Lecture –Positional Numbering Systems –Converting Between Bases Today’s Topics –Signed Integer Representation Signed magnitude One’s complement.
1 DLD Lecture 18 Recap. 2 Recap °Number System/Inter-conversion, Complements °Boolean Algebra °More Logic Functions: NAND, NOR, XOR °Minimization with.
Binary Numbers. Why Binary? Maximal distinction among values  minimal corruption from noise Imagine taking the same physical attribute of a circuit,
Cosc 2150: Computer Organization Chapter 2 Part 1 Integers addition and subtraction.
Chapter 19 Number Systems. Irvine, Kip R. Assembly Language for Intel-Based Computers, Translating Languages English: Display the sum of A times.
EEL 3801C EEL 3801 Part I Computing Basics. EEL 3801C Data Representation Digital computers are binary in nature. They operate only on 0’s and 1’s. Everything.
Data Representation Bits, Bytes, Binary, Hexadecimal.
CSC 370 (Blum)1 Binary Numbers Material on Data Representation can be found in Chapter 2 of Computer Architecture (Nicholas Carter)
PHY 201 (Blum)1 Shift registers and Floating Point Numbers Chapter 11 in Tokheim.
1 Digital Logic Design Lecture 2 More Number Systems/Complements.
CHAPTER 3: Number Systems
Number Representation and Arithmetic Circuits
CSC 331: DIGITAL LOGIC DESIGN COURSE LECTURER: E. Y. BAAGYERE. CONTACT: LECTURE TIME: 15:40 – 17:45 hrs. VENUE: SP-LAB.
PHY 201 (Blum)1 Shift registers and Floating Point Numbers Chapter 11 in Tokheim.
Floating Point Representations
Unit 1 Introduction Number Systems and Conversion.
Data Representation COE 308 Computer Architecture
Cosc 2150: Computer Organization
Binary & Hex Review.
Chapter 2 Binary Number Systems.
Binary, Denary, Hexadecimal Conversion Binary Addition
Data Representation ICS 233
Lec 3: Data Representation
Data Representation.
Digital Logic & Design Dr. Waseem Ikram Lecture 02.
Data Representation Binary Numbers Binary Addition
CHAPTER 1 : INTRODUCTION
Data Representation in Computer Systems
COMPUTING FUNDAMENTALS
Chapter 3 Data Representation
A Level Computing Component 2
Fundamentals & Ethics of Information Systems IS 201
IT 0213: INTRODUCTION TO COMPUTER ARCHITECTURE
BEE1244 Digital System and Electronics BEE1244 Digital System and Electronic Chapter 2 Number Systems.
Binary Numbers Material on Data Representation can be found in Chapter 2 of Computer Architecture (Nicholas Carter) CSC 370 (Blum)
Data Representation COE 301 Computer Organization
Number Systems and Codes
Shift registers and Floating Point Numbers
Binary Numbers Material on Data Representation can be found in Chapter 2 of Computer Architecture (Nicholas Carter) CSIT 301 (Blum)
MMNSS COLLEGE,KOTTIYAM DEPARTMENT OF PHYSICS
King Fahd University of Petroleum and Minerals
Digital Logic & Design Lecture 02.
Digital Systems and Binary Numbers
Chapter 2: Number Systems
Binary Numbers.
Chapter Four Data Representation in Computers By Bezawit E.
Data Representation ICS 233
Floating Point Numbers
Binary & Hex Review.
Data Representation COE 308 Computer Architecture
Presentation transcript:

Binary Numbers Material on Data Representation can be found in Chapter 2 of Computer Architecture (Nicholas Carter) CSIT 301 (Blum)

Can’t get away from the noise CSIT 301 (Blum)

Why Binary? Maximal distinction among values  minimal corruption from noise. Imagine taking the same physical attribute of a circuit, e.g. a voltage lying between 0 and 5 volts, to represent a number. The overall range can be divided into any number of regions. CSIT 301 (Blum)

Don’t sweat the small stuff For decimal numbers, fluctuations must be less than 0.25 volts. For binary numbers, fluctuations must be less than 1.25 volts. 5 volts 0 volts Decimal Binary CSIT 301 (Blum)

Range actually split in three High Forbidden range Low CSIT 301 (Blum)

It doesn’t matter …. Two of the standard voltages coming from a computer’s power supply are ideally supposed to be 5.00 volts and 12.00 volts Measurements often reveal values that are slightly off – e.g. 5.14 volts or 12.22 volts or some such value. So what, who cares. CSIT 301 (Blum)

How to represent big integers Use positional weighting, same as with decimal numbers 205 = 2102 + 0101 + 5100 11001101 = 127 + 126 + 025 + 024 + 123 + 122 + 021 + 120 = 128 + 64 + 8 + 4 + 1 = 205 CSIT 301 (Blum)

Converting 205 to Binary 205/2 = 102 with a remainder of 1, place the 1 in the least significant digit position Repeat 102/2 = 51, remainder 0 1 1 CSIT 301 (Blum)

Iterate 51/2 = 25, remainder 1 25/2 = 12, remainder 1 1 1 CSIT 301 (Blum)

Iterate 6/2 = 3, remainder 0 3/2 = 1, remainder 1 1/2 = 0, remainder 1 1 1 1 CSIT 301 (Blum)

Recap 205 1 127 + 126 + 025 + 024 + 123 + 122 + 021 + 120 CSIT 301 (Blum)

Finite representation Typically we just think computers do binary math. But an important distinction between binary math in the abstract and what computers do is that computers are finite. There are only so many flip-flops or logic gates in the computer. When we declare a variable, we set aside a certain number of flip-flops (bits of memory) to hold the value of the variable. And this limits the values the variable can have. CSIT 301 (Blum)

Same number, different representation 5 using 8 bits 0000 0101 5 using 16 bits 0000 0000 0000 0101 5 using 32 bits 0000 0000 0000 0000 0000 0000 0000 0101 CSIT 301 (Blum)

Adding Binary Numbers Same as decimal; if the sum of digits in a given position exceeds the base (10 for decimal, 2 for binary) then there is a carry into the next higher position 1 3 9 + 5 7 4 CSIT 301 (Blum)

Adding Binary Numbers 1 + carries 39 35 74 CSIT 301 (Blum)

Uh oh, overflow What if you use a byte (8 bits) to represent an integer A byte may not be enough to represent the sum of two such numbers. 1 170 204 118??? CSIT 301 (Blum)

Biggest unsigned* integers 4 bit: 1111  15 = 24 - 1 8 bit: 11111111  255 = 28 – 1 16 bit: 1111111111111111  65535= 216 – 1 32 bit: 11111111111111111111111111111111  4294967295= 232 – 1 Etc. *If one uses all of the bits available to represent only positive counting numbers, one is said to be working with unsigned integers. CSIT 301 (Blum)

Bigger Numbers High-level languages often offer a hierarchy of types that differ in the number of bits used. You can represent larger numbers than allowed by the highest type in the hierarchy by using more words. You just have to keep track of the overflows to know how the lower numbers (less significant words) are affecting the larger numbers (more significant words). CSIT 301 (Blum)

Negative numbers Negative x is the number that when added to x gives zero Ignoring overflow the two eight-bit numbers above add up to zero 1  x  -x CSIT 301 (Blum)

Two’s Complement: a two-step procedure for finding -x from x Step 1: exchange 1’s and 0’s Step 2: add 1 (to the lowest bit only) 1  x 1 1  -x CSIT 301 (Blum)

Sign bit With the two’s complement approach, all positive numbers start with a 0 in the left-most, most-significant bit and all negative numbers start with 1. So the first bit is called the sign bit. But note you have to work harder than just strip away the first bit. 10000001 IS NOT the 8-bit version of –1 CSIT 301 (Blum)

Add 1’s to the left to get the same negative number using more bits -5 using 8 bits 11111011 -5 using 16 bits 1111111111111011 -5 using 32 bits 11111111111111111111111111111011 When the numbers represented are whole numbers (positive or negative), they are called just integers or signed. CSIT 301 (Blum)

3-bit signed and unsigned 7 1 6 5 4 3 2 3 1 2 -1 -2 -3 -4 Think of driving a brand new car in reverse. What would happen to the odometer? CSIT 301 (Blum)

Biggest signed integers 4 bit: 0111  7 = 23 - 1 8 bit: 01111111  127 = 27 – 1 16 bit: 0111111111111111  32767= 215 – 1 32 bit: 01111111111111111111111111111111  2147483647= 231 – 1 Etc. CSIT 301 (Blum)

Most negative signed integers 4 bit: 1000  -8 = - 23 8 bit: 10000000  - 128 = - 27 16 bit: 1000000000000000  -32768= - 215 32 bit: 10000000000000000000000000000000  -2147483648= - 231 Etc. CSIT 301 (Blum)

XKCD CSIT 301 (Blum)

Some Java numerical types CSIT 301 (Blum)

Riddle 1 Is it 214? Or is it – 42? Or is it Ö? Or is it …? It’s a matter of interpretation How was it declared? 1 CSIT 301 (Blum)

Hexadecimal Numbers Even moderately sized decimal numbers end up as long strings in binary. Hexadecimal numbers (base 16) are often used because the strings are shorter and the conversion to binary is easier. There are 16 digits: 0-9 and A-F. CSIT 301 (Blum)

Decimal  Binary  Hex 0  0000  0 1  0001  1 2  0010  2 3  0011  3 4  0100  4 5  0101  5 6  0110  6 7  0111  7 8  1000  8 9  1001  9 10  1010  A 11  1011  B 12  1100  C 13  1101  D 14  1110  E 15  1111  F CSIT 301 (Blum)

Binary to Hex Break a binary string into groups of four bits (nibbles). Convert each nibble separately. 1 E C 9 CSIT 301 (Blum)

Some Hex CSIT 301 (Blum)

Numbers from Logic All of the numerical operations we have talked about are really just combinations of logical operations. E.g. the adding operation is just a particular combination of logic operations Possibilities for adding two bits 0+0=0 (with no carry) 0+1=1 (with no carry) 1+0=1 (with no carry) 1+1=0 (with a carry) CSIT 301 (Blum)

Addition Truth Table INPUT OUTPUT A B Sum A XOR B Carry A AND B 1 1 CSIT 301 (Blum)

Multiplication: Shift and add 1  + shift shift CSIT 301 (Blum)

Fractions Similar to what we’re used to with decimal numbers 3.14159 = 3 · 100 + 1 · 10-1 + 4 · 10-2 + 1 · 10-3 + 5 · 10-4 + 9 · 10-5 11.001001 = 1 · 21 + 1 · 20 + 0 · 2-1 + 0 · 2-2 + 1 · 2-3 + 0 · 2-4 + 0 · 2-5 + 1 · 2-6 (11.001001  3.140625) CSIT 301 (Blum)

Converting decimal to binary II 98.61 Integer part 98 / 2 = 49 remainder 0 49 / 2 = 24 remainder 1 24 / 2 = 12 remainder 0 12 / 2 = 6 remainder 0 6 / 2 = 3 remainder 0 3 / 2 = 1 remainder 1 1 / 2 = 0 remainder 1 1100010 CSIT 301 (Blum)

Converting decimal to binary III 98.61 Fractional part 0.61  2 = 1.22 0.22  2 = 0.44 0.44  2 = 0.88 0.88  2 = 1.76 0.76  2 = 1.52 0.52  2 = 1.04 .100111 CSIT 301 (Blum)

Another Example (Whole number part) 123.456 Integer part 123 / 2 = 61 remainder 1 61 / 2 = 30 remainder 1 30 / 2 = 15 remainder 0 15 / 2 = 7 remainder 1 7 / 2 = 3 remainder 1 3 / 2 = 1 remainder 1 1 / 2 = 0 remainder 1 1111011 CSIT 301 (Blum)

Checking: Go to All Programs/Accessories/Calculator PHY 201 (Blum)

Put the calculator in Programmer view PHY 201 (Blum)

Enter number, put into binary mode PHY 201 (Blum)

Another Example (fractional part) 123.456 Fractional part 0.456  2 = 0.912 0.912  2 = 1.824 0.824  2 = 1.648 0.648  2 = 1.296 0.296  2 = 0.592 0.592  2 = 1.184 0.184  2 = 0.368 … .0111010… CSIT 301 (Blum)

Convert to decimal mode, then PHY 201 (Blum)

Edit/Copy result. Switch to Scientific View. Edit/Paste PHY 201 (Blum)

Divide by 2 raised to the number of digits (in this case 7, including leading zero) 1 2 3 4 PHY 201 (Blum)

Finally hit the equal sign. In most cases it will not be exact PHY 201 (Blum)

Other way around Multiply fraction by 2 raised to the desired number of digits in the fractional part. For example .456  27 = 58.368 Throw away the fractional part and represent the whole number 58 111010 But note that we specified 7 digits and the result above uses only 6. Therefore we need to put in the leading 0 0111010 CSIT 301 (Blum)

Fixed point If one has a set number of bits reserved for representing the whole number part and another set number of bits reserved for representing the fractional part of a number, then one is said to be using fixed point representation. The point dividing whole number from fraction has an unchanging (fixed) place in the number. CSIT 301 (Blum)

Limits of the fixed point approach Suppose you use 4 bits for the whole number part and 4 bits for the fractional part (ignoring sign for now). The largest number would be 1111.1111 = 15.9375 The smallest, non-zero number would be 0000.0001 = .0625 CSIT 301 (Blum)

References Computer Architecture, Nicholas Carter Computer Systems: Organization and Architecture, John Carpinelli CSIT 301 (Blum)