Binary Representation Introduction to Computer Science and Programming I Chris Schmidt.

Slides:



Advertisements
Similar presentations
A-Level Computing#BristolMet Session Objectives#9 express numbers in binary, binary-coded decimal (BCD), octal and hexadecimal; describe and use two’s.
Advertisements

The Binary Numbering Systems
COMP3221: Microprocessors and Embedded Systems--Lecture 1 1 COMP3221: Microprocessors and Embedded Systems Lecture 3: Number Systems (I)
Representations Example: Numbers –145 –CVL – –91 –

Agenda Shortcuts converting among numbering systems –Binary to Hex / Hex to Binary –Binary to Octal / Octal to Binary Signed and unsigned binary numbers.
8 November Forms and JavaScript. Types of Inputs Radio Buttons (select one of a list) Checkbox (select as many as wanted) Text inputs (user types text)
CSCE 211: Digital Logic Design Chin-Tser Huang University of South Carolina.
Number Representation (1) Fall 2005 Lecture 12: Number Representation Integers and Computer Arithmetic.
Data Representation ICS 233
Binary and Decimal Numbers
Review Binary Basic Conversion Binary Decimal
Codes and number systems Introduction to Computer Yung-Yu Chuang with slides by Nisan & Schocken ( ) and Harris & Harris (DDCA)
COMP201 Computer Systems Number Representation. Number Representation Introduction Number Systems Integer Representations Examples  Englander Chapter.
Number Systems Computer Science 210 Computer Organization.
Binary Number Systems.
Binary Representation and Computer Arithmetic
The Binary Number System
Data Representation Number Systems.
ECE 2110: Introduction to Digital Systems Signed Number Conversions.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Integer Data representation Addition and Multiplication.
Simple Data Type Representation and conversion of numbers
Higher Computing Data Representation.
Abstraction – Number Systems and Data Representation.
Lecture 5.
Numbers and Number Systems
CMPT 120 How computers run programs Summer 2012 Instructor: Hassan Khosravi.
2-1 Chapter 2 - Data Representation Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Chapter Contents.
NUMBER REPRESENTATION CHAPTER 3 – part 3. ONE’S COMPLEMENT REPRESENTATION CHAPTER 3 – part 3.
Data Representation.
Number Systems. Today Decimal Hexadecimal Binary –Unsigned Binary –1’s Complement Binary –2’s Complement Binary.
46 Number Systems Problem: Implement simple pocket calculator Need: Display, adders & subtractors, inputs Display: Seven segment displays Inputs: Switches.
Representation of Data Ma King Man. Reference Text Book: Volume 2 Notes: Chapter 19.
Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.
The Teacher CP4 Binary and all that… CP4 Revision.
BR 8/99 Binary Numbers Again Recall than N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to 255.
Number Representation
Lecture 2 Binary Values and Number Systems. The number 943 is an example of a number written in positional notation. The relative positions of the digits.
CISC1100: Binary Numbers Fall 2014, Dr. Zhang 1. Numeral System 2  A way for expressing numbers, using symbols in a consistent manner.  " 11 " can be.
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.
Computer Math CPS120 Introduction to Computer Science Lecture 4.
Data Representation Bits, Bytes, Binary, Hexadecimal.
Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, Signed Integers The highest bit indicates the sign. 1 = negative, 0 = positive.
69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1, * *10 + 4*1 n Alternate view: Digit position.
©Brooks/Cole, 2003 Chapter 3 Number Representation.
Lecture 2: 8/29/2002CS149D Fall CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
Nguyen Le CS147.  2.4 Signed Integer Representation  – Signed Magnitude  – Complement Systems  – Unsigned Versus Signed Numbers.
Data Representation COE 301 Computer Organization Dr. Muhamed Mudawar
 Computers are 2-state devices › Pulse – No pulse › On – Off  Represented by › 1 – 0  BINARY.
Number Systems Part 2. Counting in Binary DecimalBinary
Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:
Advanced Binary b. describe and use two’s complement and sign and magnitude to represent negative integers; c. perform integer binary arithmetic, that.
Data Representation COE 301 Computer Organization Prof. Muhamed Mudawar College of Computer Sciences and Engineering King Fahd University of Petroleum.
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Binary & Hex Review.
Computer Science 210 Computer Organization
Number Representation
3.1 Denary, Binary and Hexadecimal Number Systems
Lesson Objectives Aims
Computer Science 210 Computer Organization
EPSII 59:006 Spring 2004.
CSE 102 Introduction to Computer Engineering
Number Systems.
Computer Science 210 Computer Organization
Data Representation Data Types Complements Fixed Point Representation
Computer Science 210 Computer Organization
Computer Architecture CST 250
WJEC GCSE Computer Science
Presentation transcript:

Binary Representation Introduction to Computer Science and Programming I Chris Schmidt

Binary Representation Computers store and process all information in binary, a series bits, 1s and 0s Computers store and process all information in binary, a series bits, 1s and 0s How does the computer represent this information that the user only sees as numbers and text? How does the computer represent this information that the user only sees as numbers and text?

Binary Representation Bit: smallest element, either 0 or 1 Bit: smallest element, either 0 or 1 Byte: grouping of 8 bits, Byte: grouping of 8 bits, kilobyte: 2 10 = 1024 bytes kilobyte: 2 10 = 1024 bytes megabyte: 2 20 = bytes megabyte: 2 20 = bytes gigabyte: 2 30 bytes gigabyte: 2 30 bytes terabyte: 2 40 bytes terabyte: 2 40 bytes

Decimal Numbers How do we (usually) work with numbers? How do we (usually) work with numbers? Decimal system aka Base 10 Decimal system aka Base 10 Uses the 10 digits 0,1,2,3,4,5,6,7,8,9 Uses the 10 digits 0,1,2,3,4,5,6,7,8, = = 4 * * * * = = 4 * * * * 10 0 Going from right to left each digits tells us the count for each power of 10 starting at 0 Going from right to left each digits tells us the count for each power of 10 starting at 0

Other Number Systems Binary, Base 2 Binary, Base 2 2 digits, 0 and 1 2 digits, 0 and = 1 * * * * 2 0 = = = 1 * * * * 2 0 = = Octal, Base 8 Octal, Base 8 8 digits, 0 thru 7 8 digits, 0 thru = 3 * * 8 0 = = = 3 * * 8 0 = = Hexadecimal, Base 16 Hexadecimal, Base digits, 0 thru 9,A,B,C,D,E,F 16 digits, 0 thru 9,A,B,C,D,E,F 12B 16 = 1 * * * 16 0 = = B 16 = 1 * * * 16 0 = =

Binary How does a computer store decimal numbers in binary? How does a computer store decimal numbers in binary? Can we just convert the number to binary and store it? Can we just convert the number to binary and store it? If we are looking at unsigned (positive) numbers, Yes If we are looking at unsigned (positive) numbers, Yes However, things get more complicated when we want to store positive and negative numbers. However, things get more complicated when we want to store positive and negative numbers.

Binary For the time being we’ll work with 4 digit numbers only For the time being we’ll work with 4 digit numbers only How many numbers can be represented by a 4 digit decimal number? How many numbers can be represented by a 4 digit decimal number? 0 thru 9999 ( ), 10 5 different numbers 0 thru 9999 ( ), 10 5 different numbers Binary? Binary? 0 thru 1111 (2 5 -1) = 2 5 different numbers 0 thru 1111 (2 5 -1) = 2 5 different numbers

Unsigned Binary BinaryDecimal

Signed Magnitude Simplest solution to store negative numbers, use a bit to represent the sign Simplest solution to store negative numbers, use a bit to represent the sign 1=negative, 0=positive 1=negative, 0=positive = 7, = = 7, = = 4, = = 4, = -4 This is called signed magnitude because the first bit gives the sign and the rest gives the magnitude of the number This is called signed magnitude because the first bit gives the sign and the rest gives the magnitude of the number Simple, but there is a problem Simple, but there is a problem 1000 = 0000 = = 0000 = 0 Two representations of the same number Two representations of the same number Can complicate processing Can complicate processing Not using space most efficiently Not using space most efficiently

Two’s Complement Two’s complement is the binary representation usually used to represent positive or negative integers Two’s complement is the binary representation usually used to represent positive or negative integers Unlike the previous representation, every value has a single representation Unlike the previous representation, every value has a single representation

Two’s Complement First bit tells you whether it is positive or negative (0-positive, 1-negative), but is also part of the number First bit tells you whether it is positive or negative (0-positive, 1-negative), but is also part of the number Positive numbers are simply the binary representation of the number Positive numbers are simply the binary representation of the number 0010 = = = = 7 7 (2 4 – 1) is the largest possible number representable in 4 bit 2’s complement (otherwise the first bit would be a 1) 7 (2 4 – 1) is the largest possible number representable in 4 bit 2’s complement (otherwise the first bit would be a 1)

Two’s Complement Negative numbers Negative numbers A 1 as the leftmost bit means it is negative A 1 as the leftmost bit means it is negative To find the number’s magnitude, work from right to left. Leave the 0s and the first 1 be, reverse the rest of the bits To find the number’s magnitude, work from right to left. Leave the 0s and the first 1 be, reverse the rest of the bits 1111 = = = = = = = = = = = = = = = = = = = = -8 Same process to go in reverse direction Same process to go in reverse direction

Two’s Complement Advantages Advantages As mentioned, single representation for each number As mentioned, single representation for each number Single bit to check to know if number is positive or negative Single bit to check to know if number is positive or negative For positive numbers, unsigned and 2’s complement representation are the same For positive numbers, unsigned and 2’s complement representation are the same Simple arithmetic, addition and subtraction are done by (almost) the same method as normal addition and subtraction Simple arithmetic, addition and subtraction are done by (almost) the same method as normal addition and subtraction

Range What numbers can be represented given n bits (32 is typical for computers) What numbers can be represented given n bits (32 is typical for computers) Unsigned Unsigned 0 thru (2 n -1), 2 n different values 0 thru (2 n -1), 2 n different values Signed Magnitude Signed Magnitude -(2 n-1 -1) thru (2 n-1 -1), 2 n -1 different values -(2 n-1 -1) thru (2 n-1 -1), 2 n -1 different values Two’s Complement Two’s Complement -2 n-1 thru (2 n-1 -1), 2 n different values -2 n-1 thru (2 n-1 -1), 2 n different values

Binary Values DigitsUnsignedSigned Magnitude2s Complement

Floating Point Number We’ve only talked about how to represent integer values in binary We’ve only talked about how to represent integer values in binary Floating point numbers (numbers that can have a decimal point) e.g. 1.5, require a more complex representation that we won’t get into Floating point numbers (numbers that can have a decimal point) e.g. 1.5, require a more complex representation that we won’t get into

Text Representation Computer needs to store text Computer needs to store text Single characters A 2 $ space newline Single characters A 2 $ space newline Strings of characters “Chris” “1-A” Strings of characters “Chris” “1-A” Simple solution Simple solution Associate each character with number Associate each character with number Store the binary value for that number Store the binary value for that number

ASCII Each character represented by one byte (actually just 7 of the 8 bits are needed) Each character represented by one byte (actually just 7 of the 8 bits are needed) Contains all of the characters needed for English text, but insufficient for many languages Contains all of the characters needed for English text, but insufficient for many languages

ASCII Table

Unicode A character set that has been designed to store the characters for all written languages A character set that has been designed to store the characters for all written languages More bits required to store the characters More bits required to store the characters

Strings Simply store the ASCII values for characters in the string one after the other Simply store the ASCII values for characters in the string one after the other Using the ASCII character set Using the ASCII character set H = 72 = H = 72 = i = 105 = i = 105 = “Hi” = “Hi” =