Topic: Binary Encoding – Part 2

Slides:



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

2-1 Computer Organization Part Fixed Point Numbers Using only two digits of precision for signed base 10 numbers, the range (interval between lowest.
1 CSE1301 Computer Programming Lecture 28 Number Representation (Integer)
Data Representation ICS 233
Data Representation in Computers
Lecture 5.
Binary Representation. Binary Representation for Numbers Assume 4-bit numbers 5 as an integer  as an integer  How? 5.0 as a real number  How?
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 1 Today’s Topics How information.
2-1 Chapter 2 - Data Representation Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Chapter Contents.
Data Representation.
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
Lecture 5. Topics Sec 1.4 Representing Information as Bit Patterns Representing Text Representing Text Representing Numeric Values Representing Numeric.
Number Representation
AEEE2031 Data Representation and Numbering Systems.
Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, Signed Integers The highest bit indicates the sign. 1 = negative, 0 = positive.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Digital Representations ME 4611 Binary Representation Only two states (0 and 1) Easy to implement electronically %0= (0) 10 %1= (1) 10 %10= (2) 10 %11=
©Brooks/Cole, 2003 Chapter 3 Number Representation.
Computer Organization 1 Data Representation Negative Integers.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
Data Representation COE 301 Computer Organization Dr. Muhamed Mudawar
Data Representation COE 301 Computer Organization Prof. Muhamed Mudawar College of Computer Sciences and Engineering King Fahd University of Petroleum.
ECE 2110: Introduction to Digital Systems Signed Number Conversions.
Representing Positive and Negative Numbers
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Department of Computer Science Georgia State University
Data Representation COE 308 Computer Architecture
Topic: Binary Encoding – Part 1
David Kauchak CS 52 – Spring 2017
Data Representation ICS 233
Lec 3: Data Representation
Data Representation.
Negative Numbers and Subtraction
CHAPTER 9 COMPUTER ARITHMETIC - ALU
Negative Binary Numbers
3.1 Denary, Binary and Hexadecimal Number Systems
Introduction To Computer Science
Recap Add these numbers together in binary
Digital Logic & Design Dr. Waseem Ikram Lecture 02.
Data Representation Binary Numbers Binary Addition
Integer Real Numbers Character Boolean Memory Address CPU Data Types
Chapter 3 Data Storage.
Computer Science 210 Computer Organization
Numbers in a Computer Unsigned integers Signed magnitude
Negative Binary Numbers
Lesson objectives Understand how computers represent and manipulate numbers [unsigned integers, signed integers (sign and magnitude, Two’s complement)
Number Systems.
Data Structures Mohammed Thajeel To the second year students
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
TAO1221 COMPUTER ARCHITECTURE AND ORGANIZATION LAB 6
Computer Science 210 Computer Organization
Data Representation COE 301 Computer Organization
Data Representation Data Types Complements Fixed Point Representation
Topic 3 Number Representations and Computer Arithmetics
Fundamentals of Programming I Number Systems
Subtraction The arithmetic we did so far was limited to unsigned (positive) integers. Today we’ll consider negative numbers and subtraction. The main problem.
Digital Logic & Design Lecture 02.
Information Representation
COMS 161 Introduction to Computing
Topic 3 Number Representations and Computer Arithmetics
Number Representation
Storing Negative Integers
How Computers Store Data
Chapter 3 DataStorage Foundations of Computer Science ã Cengage Learning.
Data Representation ICS 233
OBJECTIVES After reading this chapter, the reader should be able to :
靜夜思 床前明月光, 疑是地上霜。 舉頭望明月, 低頭思故鄉。 ~ 李白 李商隱.
Lecture 35 – Unit 6 – Under the Hood Binary Encoding – Part 1
Lecture 36 – Unit 6 – Under the Hood Binary Encoding – Part 2
Data Representation COE 308 Computer Architecture
Presentation transcript:

Topic: Binary Encoding – Part 2 CMPT 120 Topic: Binary Encoding – Part 2

Decimal numeral system Last Lecture Binary Encoding How characters are represented in computer memory How numbers are represented in computer memory But before to do this, we need to introduce decimal and binary numeral systems Counting and adding numbers in these numeral systems Converting binary numbers <-> decimal numbers Decimal numeral system Binary numeral system

Learning Outcomes At the end of this course, a student is expected to: Manipulate binary encodings of simple data types. Do conversions from binary system to decimal and vice versa Determine the range of representable values within binary system Do additions and incremental counting within binary system Decode/encode a bit string to/from its corresponding value (unsigned, 2's complement, ASCII)

Today’s Menu Binary encoding How numbers integers are represented in computer memory Unsigned integers Signed integers Sign and magnitude 1’s complement 2's complement How many values can they represent -> range of values

How integers are represented in computer memory? Representing an integer in computer memory is often called fixed point representation (or notation) Size of computer memory location in which an integer is stored is a factor of 8 bits (1 byte) For example: 8-bit fixed point representation -> 16-bit “ “ “ -> 32-bit “ “ “ -> 64-bit “ “ “ -> Two types of integers: unsigned and signed

Unsigned versus signed integer Unsigned integer Signed integer

How unsigned integers are represented in computer memory? unsigned integers are stored in computer memory locations of x-bit size where x can be 8, 16, 32, 64 Example:

Range of values of an unsigned integer If the computer memory location containing an unsigned integer is of size x-bit where x = 8, how many different values can this unsigned integer have?

In general… The range of an unsigned integer is [0 .. 2x-1] If x = 8 -> [0 .. 28-1] = [0 .. 255] If x = 16 -> [0 .. 216-1] = [0 .. ] If x = 32 -> [0 .. 232-1] = [0 .. ] If x = 64 -> [0 .. 264-1] = [0 .. ] An unsigned integer can have 2x different values If x = 8 -> 28 = 256 If x = 16 -> 216 = If x = 32 -> 232 = If x = 64 -> 264 = Note that, aside from 0, all of these values are positive

How positive signed integers are represented in computer memory? positive signed integers are stored in computer memory locations of x-bit size where x can be 8, 16, 32, 64 Example:

How negative signed integers are represented in computer memory? are also stored in computer memory locations of x-bit size where x can be 8, 16, 32, 64 are represented using the following conventions: Sign and magnitude 1’s complement 2’s complement All conventions: sign represented by leftmost bit 0 for positive integer 1 for negative integer

A. Sign and magnitude Let’s store the integer _______ in an 8-bit memory location using the sign and magnitude convention: Convert the absolute value of the integer to a binary # Pad the resulting binary number to fill a size of 8-bit Set the sign bit (leftmost bit) to appropriate value -> 1

B. 1’s Complement Let’s store the integer _______ in an 8-bit memory location using the 1’s complement convention: Convert the absolute value of the integer to a binary # Pad the resulting binary number to fill a size of 8-bit Flip all the bits!

C. 2’s Complement Let’s store the integer _______ in an 8-bit memory location using the 2’s complement convention: Convert the absolute value of the integer to a binary # Pad the resulting binary number to fill a size of 8-bit Flip all the bits! Then, add 12.

Which convention does the computer use? 2’s complement Why? To understand why, let’s have a look at the table on the next slide!

x = 8 Decimal 2’s complement 1’s complement Sign and magnitude +7 00000111 +6 00000110 +5 00000101 +4 00000100 +3 00000011 +2 00000010 +1 00000001 +0 00000000 -0 11111111 10000000 -1 11111110 10000001 -2 11111101 10000010 -3 11111100 10000011 -4 11111011 10000100 -5 11111010 10000101 -6 11111001 10000110 -7 11111000 10000111 -8 11110111 10001000 x = 8

Converting back To convert a 2’s complement negative signed integer back to its decimal equivalent: Flip all the bits! Then, add 12. Convert this binary number back to a signed integer

Range of value of a signed integer The range of a signed integer is [-2x-1 .. 2x-1-1] If x = 8, then the range a signed integer is [-28-1 .. 28-1-1] = [-27 .. 27-1] = [-128 .. 127] A signed integer can also have 2x different values If x = 8, then a signed integer can also have 28 = 256 different values, i.e., any of the value in the range -128 to 127 Note that, aside from 0, half of these values are negative and the other half (-1) are positive

In general… The range of an signed integer is [-2x-1 .. 2x-1-1] If x = 8 -> [-28-1 .. 28-1-1] = [-27 .. 27-1] = [-128 .. 127] If x = 16 -> [-216-1 .. 216-1-1] If x = 32 -> [-232-1 .. 232-1-1] If x = 64 -> [-264-1 .. 264-1-1] An signed integer can have 2x different values If x = 8 -> 28 = 256 If x = 16 -> 216 = If x = 32 -> 232 = If x = 64 -> 264 = Note that, aside from 0, half of these values are negative and the other half (-1) are positive

When to use a unsigned integer as opposed to a signed integer Imagine we are developing a database application We represent the number of elements in our database using a variable elementCount What would the data type of this variable be? In other words, how would we represent this variable in the computer memory? Let’s assume 16-bit memory location Impact of choosing data type signed integer Range of values: [-32768 to 32767] Since this variable will only be assigned either 0 or a positive value (we cannot have a negative number representing the number of elements in our database), only half of the range of the signed integer, namely 0 to 32767 (32768 values) is available to us Impact of choosing the data type unsigned integer Range of values: [0 to 65535] Since this variable will only be assigned either 0 or a positive value (we cannot have a negative number representing the number of elements in our database), the range of values available to us is 65536 different values Hence, twice has many values as if we choose to represent this variable (in the computer memory) using a signed integer 

Summary Binary encoding 01101000101001010010011011110010 How integers are represented in computer memory Unsigned integers Signed integers Sign and magnitude 1’s complement 2's complement How many values can they represent -> range of values The meaning of a sequence of 0’s and 1’s in x bytes in memory, such as: 01101000101001010010011011110010 is determined by the context, as it could be Unicode character, an integer, a floating point number, a colour, a sound, a microprocessor (CPU) instruction, etc …

Next Lecture Searching algorithms