Review of Data Representation & Binary Operations Dhananjai M. Rao CSA Department Miami University

Similar documents
CS & IT Conversions. Magnitude 10,000 1,

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

Digital Fundamentals. CHAPTER 2 Number Systems, Operations, and Codes

Numeral Systems. -Numeral System -Positional systems -Decimal -Binary -Octal. Subjects:

SCHOOL OF ENGINEERING & BUILT ENVIRONMENT. Mathematics. Numbers & Number Systems

DLD VIDYA SAGAR P. potharajuvidyasagar.wordpress.com. Vignana Bharathi Institute of Technology UNIT 1 DLD P VIDYA SAGAR

Bits, Words, and Integers

Chapter 2: Number Systems

Number System. Introduction. Decimal Numbers

CC411: Introduction To Microprocessors

Dec Hex Bin ORG ; ZERO. Introduction To Computing

Number representations

CHW 261: Logic Design

CMPS 10 Introduction to Computer Science Lecture Notes

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

Number Systems. Dr. Tarek A. Tutunji Philadelphia University, Jordan

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

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

1.1. INTRODUCTION 1.2. NUMBER SYSTEMS

Chapter 4. Operations on Data

Number Systems CHAPTER Positional Number Systems

MC1601 Computer Organization

Module 1: Information Representation I -- Number Systems

Objectives. Connecting with Computer Science 2

Lecture 2: Number Systems

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

TOPICS. Other Number Systems. Other Number Systems 9/9/2017. Octal Hexadecimal Number conversion

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

THE LOGIC OF COMPOUND STATEMENTS

umber Systems bit nibble byte word binary decimal

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

Number Systems. Both numbers are positive

plc numbers Encoded values; BCD and ASCII Error detection; parity, gray code and checksums

DIGITAL SYSTEM DESIGN

Chapter 2. Data Representation in Computer Systems

The. Binary. Number System

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

Computer Number Systems Supplement

Introduction to Computers and Programming. Numeric Values

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 01, SPRING 2013

ELECTRICAL AND COMPUTER ENGINEERING DEPARTMENT, OAKLAND UNIVERSITY ECE-278: Digital Logic Design Fall Notes - Unit 4. hundreds.

DATA REPRESENTATION. By- Neha Tyagi PGT CS KV 5 Jaipur II Shift, Jaipur Region. Based on CBSE curriculum Class 11. Neha Tyagi, KV 5 Jaipur II Shift

Chapter 2 Bits, Data Types, and Operations

Octal & Hexadecimal Number Systems. Digital Electronics

ELECTRICAL AND COMPUTER ENGINEERING DEPARTMENT, OAKLAND UNIVERSITY ECE-2700: Digital Logic Design Winter Notes - Unit 4. hundreds.

4 Operations On Data 4.1. Foundations of Computer Science Cengage Learning

Chapter 1 Preliminaries

Chapter 2 Exercises and Answers

Digital Fundamentals

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

Binary, Hexadecimal and Octal number system

What Is It? Instruction Register Address Register Data Register

CMPE223/CMSE222 Digital Logic Design. Positional representation

Moodle WILLINGDON COLLEGE SANGLI. ELECTRONICS (B. Sc.-I) Introduction to Number System

Octal and Hexadecimal Integers

Digital Systems and Binary Numbers

Lecture (01) Digital Systems and Binary Numbers By: Dr. Ahmed ElShafee

CHAPTER 2 Number Systems

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

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

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

Bits, bytes, binary numbers, and the representation of information

Chapter 2 Bits, Data Types, and Operations

2 Number Systems 2.1. Foundations of Computer Science Cengage Learning

EE292: Fundamentals of ECE

Number Systems and Their Representations

Chapter 2 Bits, Data Types, and Operations

Digital Systems and Binary Numbers

Number Systems Using and Converting Between Decimal, Binary, Octal and Hexadecimal Number Systems

Lecture (01) Introduction Number Systems and Conversion (1)

Introduction to Numbering Systems

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

Chapter 4 Arithmetic Functions

Internal Data Representation

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

Appendix. Numbering Systems. In This Appendix...

Chapter 3 DATA REPRESENTATION

Logic Circuits I ECE 1411 Thursday 4:45pm-7:20pm. Nathan Pihlstrom.

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

Slide Set 1. for ENEL 339 Fall 2014 Lecture Section 02. Steve Norman, PhD, PEng

DIGITAL SYSTEM FUNDAMENTALS (ECE 421) DIGITAL ELECTRONICS FUNDAMENTAL (ECE 422) COURSE / CODE NUMBER SYSTEM

Appendix. Numbering Systems. In this Appendix

ENE 334 Microprocessors

T02 Tutorial Slides for Week 2

D I G I T A L C I R C U I T S E E

Excerpt from: Stephen H. Unger, The Essence of Logic Circuits, Second Ed., Wiley, 1997

MACHINE LEVEL REPRESENTATION OF DATA

Review of Number Systems

Lecture 8: Addition, Multiplication & Division

Binary Adders: Half Adders and Full Adders

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

Level ISA3: Information Representation

Ms Sandhya Rani Dash UNIT 2: NUMBER SYSTEM AND CODES. 1.1 Introduction

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

LANGUAGE CONSTRUCTS AND CONVENTIONS IN VERILOG

Computer Organization and Assembly Language. Lab Session 01

Number Systems MA1S1. Tristan McLoughlin. November 27, 2013

Hexadecimal Numbers. Journal: If you were to extend our numbering system to more digits, what digits would you use? Why those?

Numbers and Representations

Signed Binary Numbers

Transcription:

Review of Data Representation & Binary Operations Dhananjai M. Rao () CSA Department Miami University 1. Introduction In digital computers all data including numbers, characters, and strings are ultimately represented, stored, and processed as a set of Binary Digits or bits. A bit stores either a binary value, namely a 0 or a 1. Essentially a bit can be used to represent only 2 different values based on interpretation and context. For example, if bits are associated with colors, then 0 could be used to indicate the color red while 1 could be used to indicate the color blue. On the other hand, if bits are associated with characters, then 0 could be used to indicate the Greek letter while 1 indicates. In order to represent more than 2 different values, a group of bits need to be used. Given, n bits, 2 n different values can be represented using different combinations of 1 s and 0 s. For example, given 3 bit positions, 2 3 or 8 different values can be represented. Recollect that the actual value that each combination represents depends on the context and interpretation. For example, assume that 3 bits are used to represent colors then one possible interpretation is shown in the table 1 below: Bit pattern Color Bit pattern Color 000 Black 100 Red 001 Blue 101 Magenta 010 Green 110 Tan 011 Cyan 111 Grey Similar to colors, various combinations of bit values are also used to represent numbers and characters in computers. However, in order to ensure consistent interpretation of bits a number of conventions and standards have been developed to represent numbers and characters in modern computers. 1 The color codes shown in the table are actually used in practice in today s computers to display colored characters in text display modes. Page 1 of 14

2. Unsigned Integer Number Representation Decimal numbers are represented using base-10 system using 10 distinct symbols namely 0 to 9 and increasing powers of 10. For example, the number 678 (six hundred and seventy eight) consists of 3 decimal digits, with 8 in the units (10 0 ) place, 7 in the tens (10 1 ) place, and 6 in the hundredths (10 2 ) place. In other words, 678 = (6*10 2 ) + (5*10 1 ) + (2*10 0 ). Similar to the decimal system of numbers represented using base-10, numbers are represented with bits ( 0 s and 1 s) using a base-2 system or binary. For example, the binary number 110 2 corresponds to (1*2 2 )+(1*2 1 )+(0*2 0 ) = 6 10 in the decimal system. Note the use of subscripts (X 2 or Y 10 ) indicating the base in which the numbers are expressed. It is important to remember that 100 2 100 10. i. Binary (base-2) to Decimal (base-10) conversion: As indicated in the example, binary numbers are converted to decimal numbers through successive multiplication by powers of 2 and adding them. Here are a few more examples to further illustrate the process: 1101 2 = 1*2 3 + 1*2 2 + 0*2 1 + 1*2 0 = 13 10 111 2 = 1*2 2 + 1*2 1 + 1*2 0 = 7 10 1 2 = 1*2 0 = 1 10 Useful facts: 0 2 = 0*2 0 = 0 10 Even numbers always have a 0 in the units place in a unsigned binary number. Odd numbers always have a 1 in the units place in an unsigned binary number. Given n bits, the range of unsigned numbers that can be represented in binary is 0 10 to 2 n -1. For example if the number of bits n = 8, then the range of numbers that can be presented are 0 10 to 2 8-1=255. Page 2 of 14

ii. Decimal (base-10) to Binary (base-2) conversion: Converse to the earlier approach, decimal numbers are converted to binary through successive division by 2 and using the remainders as the binary digit. For example, the decimal number 27 10 is converted to binary through successive division (until the quotient is 1) and writing the remainders in reverse order, as shown below: 2 26 Remainder 2 13 0 2 6 1 2 3 0 1 1 27 10 = 11010 2 Here are a couple of more examples to further illustrate the process: 2 15 Remainder 2 7 1 2 3 1 1 1 15 10 = 1111 2 Useful facts: 2 36 Remainder 2 18 0 2 9 0 2 4 1 2 2 0 1 0 36 10 = 100100 2 In order to represent an unsigned decimal number k in binary at least 2 k bits are needed. Page 3 of 14

3. Signed Integer Representation (2 s Complement) Signed integers maybe represented using a variety of different schemes. Amongst the various schemes the 2 s Complement mechanism for representing signed integers is the most prevalent representation used in modern computers. 2 s complement representation is used for representing both positive and negative numbers in the following manner: Note: In 2 s complement, the maximum number of bits that maybe used to represent a number must be known and plays a crucial role to enable representation. i. Decimal to 2 s Complement Conversion: a. Positive number: Positive numbers are represented using the same approach for unsigned numbers explained earlier in Section 2.ii. Zeros are padded to the beginning of the binary number to expand it to the needed bit size. For example the 8-bit binary representation for +13 10 = 00001101 2 (note the 8 bits in the number with 4 leading zero bits) b. Negative number: In the case of negative numbers, the following steps are performed: 1. The number is considered as positive and the zero padded binary representation is first obtained as illustrated in Section 2.ii. For example, if 14 10 is to be represented in 2 s complement, first the 8-bit binary representation of 14 10 is determined: 14 10 = 00001110 2 2. Next all the bits are complemented, that is 1 s are made 0 s and 0 s are made 1 s. Continued from earlier step: 00001110 2 Complement 11110001 2 3. Next binary 1 2 is added to the number to obtain the final representation in of a negative number in 2 s complement. Continuing with example from step 2: 11110001 + 00000001 11110010 That is, -14 10 = 11110010 2 in 2 s complement representation. Here are a couple of more examples to illustrate the process of representing positive and negative numbers in 8-bit 2 s complement: Page 4 of 14

Useful facts: 27 10 = 00011011 2-27 10 = (00011011 2 Complement 11100100 2 + 1 2 ) = 11100101 2-121 10 = (01111001 2 Complement 10000110 2 + 1 2 ) = 10000111 2 Note: In the above 2 s complement binary representation, the most significant bit is bold and underlined (that is: 0 or 1) while the least significant bit is just underlined. Given n bits, the range of numbers that can be represented using 2 s complement is -2 n-1 to 2 n-1 1. The most significant bit (bit with highest power of 2) should always be 0 for positive numbers. The most significant bit (bit with highest power of 2) should always be 1 for negative numbers. In the case of negative numbers, the actual binary representation changes as the number of bits used for representation changes. ii. 2 s Complement to Decimal Conversion: Converting a binary number represented in 2 s complement is performed in the following manner: 1. Inspect the most significant bit of the binary number. If the bit is a 0 then it is a positive number and perform step 2. If the most significant bit is a 1 then it is a negative number and perform step 3. 2. For positive numbers, simply convert the number using the standard conversion of multiplication by increasing powers of 2 and adding them together. See earlier section 2.i for details and examples. 3. For negative numbers, perform the following steps: (a) First all the bits are complemented, that is 1 s are made 0 s and 0 s are made 1 s. (b) Next binary 1 2 is added to the number to obtain the binary representation in unsigned form. (c) Convert the binary number to decimal (using repeated multiplication by powers of 2 and addition as illustrated in Section 2.i) and place a negative sign before the number. Page 5 of 14

iii. Examples of 2 s Complement to Decimal Conversion: Convert 10000111 2 to decimal: i. To begin with, note that the most significant bit is a 1. Therefore, this value in 2 s complement represents a negative number! ii. First, complement all the bits (convert all 1 s to 0 s and 0 s to 1 s) to get: 10000111 2 Complement 01111000 2 iii. Next add binary 1 2 to the above value to get: 01111000 2 + 1 2 = 01111001 2 iv. Convert the binary to decimal (using repeated multiplication by powers of 2 and addition as illustrated in Section 2.i) to get: 121 v. Now place a negative sign before the number to get: -121 10 Convert 00000111 2 to decimal: i. To begin with, note that the most significant bit is a 0. Therefore, this value in 2 s complement represents a positive number! ii. Simply convert the binary to decimal (using repeated multiplication by powers of 2 and addition as illustrated in Section 2.i) to get: 7 10 Convert 11111000 2 to decimal: vi. To begin with, note that the most significant bit is a 1. Therefore, this value in 2 s complement represents a negative number! vii. First, complement all the bits (convert all 1 s to 0 s and 0 s to 1 s) to get: 11111000 2 Complement 00000111 2 viii. Next add binary 1 2 to the above value to get: 00000111 2 + 1 2 = 00001000 2 ix. Convert the binary to decimal (using repeated multiplication by powers of 2 and addition as illustrated in Section 2.i) to get: 8 x. Now place a negative sign before the number to get: -8 10 Page 6 of 14

4. Hexadecimal Representation (Base-16) Similar to decimal (base-10) or binary (base -2) system, Hexadecimal system uses Base- 16. Note that the base (10, 2, or 16) indicates the number of unique symbols required to represent the different values. In other words, hexadecimal (hex for short) representation requires 16 unique symbols to represent values from 0 through 15. Accordingly, the first 10 values 0 through 9 are represented using the same decimal digits while values 10 through 15 are represented using the first 6 English alphabets namely A through F. The following table lists the decimal, binary, and hexadecimal values of the first 20 numbers: Decimal Binary(5-bits) Hexadecimal Decimal Binary(5-bits) Hexadecimal 0 10 00000 2 0 16 10 10 01010 2 A 16 1 10 00001 2 1 16 11 10 01011 2 B 16 2 10 00010 2 2 16 12 10 01100 2 C 16 3 10 00011 2 3 16 13 10 01101 2 D 16 4 10 00100 2 4 16 14 10 01110 2 E 16 5 10 00101 2 5 16 15 10 01111 2 F 16 6 10 00110 2 6 16 16 10 10000 2 10 16 7 10 00111 2 7 16 17 10 10001 2 11 16 8 10 01000 2 8 16 18 10 10010 2 12 16 9 10 01001 2 9 16 19 10 10011 2 13 16 i. Binary to Hexadecimal Conversion: Binary to hexadecimal conversion is pretty straightforward and is performed by grouping sets of 4 bits (or nibbles) and writing the corresponding hex value for it. The grouping is performed from the least significant bit to the most significant bit (or right to left). Here is a detailed example illustrating the conversion process: Convert 10110110 2 to hex o First group the bits in sets of 4 from left to right to get: 1011, 0110 o For each nibble write out the hexadecimal equivalent to get: B, 6 o Write the digits together to obtain the hex representation: B6 16 Here are a few more examples: 101 2 = 5 16 10111 2 = (1, 0111) = 17 16 53 10 = 110101 2 = (11, 0101) = 35 16 Page 7 of 14

ii. Hexadecimal to Binary conversion: Conversion from hexadecimal to binary is pretty straightforward and can be performed by simply writing out the binary nibbles for each digit. Here are a few examples: 27 16 = 0010, 0111 = 100111 2 5A 16 = 0101, 1010 = 1011010 2 CC 16 = 1100, 1100 = 11001100 2 iii. Hexadecimal to Decimal conversion: Hexadecimal numbers can be converted to decimal values through successive multiplication by increasing powers of 16 and summing up the values. Here are a few examples to illustrate this technique: 27 16 = (2*16 1 ) + (7*16 0 ) = 32 + 7 = 39 10 DCC 16 = (13*16 2 ) + (12*16 1 ) + (12*16 0 ) = 3328 + 192 + 12 = 3532 10 10 16 = (1*16 1 ) + (0*16 0 ) = 16 + 0 = 16 10 9 16 = (9*16 0 ) = 9 = 9 10 Page 8 of 14

5. Character Representation (ASCII) Similar to numbers, different combinations of bits are used represent different characters in modern computers. The most prevalent standard for representing characters is ASCII. Default ASCII representation uses 7-bits to represents characters. Here are some standard representations obtained from the ASCII standard: ASCII Code Character 32 Space 42 * 48 57 0 9 65 90 A Z 97 122 a z Page 9 of 14

6. Bit-wise Operators Bit-wise operations are important and powerful transformations to numbers. Consequently, almost all high level programming languages include bit-wise operators in them. In order to effectively use bit-wise operators, you must have a good understanding of their operations and work. All of the operations share the following characteristics: Each operator works only with 1 bit at a time. However, the overall result is always a group of bits and is considered as a single unit. Operands to the bit-wise operators must be exactly the same size. Bit-wise operations are performed without paying heed to the actual representation of the binary number. However, the results from the operations are interpreted using the appropriate number representation. Given a non-binary number, you have to first convert it to binary, perform the specified bit-wise operation, and then convert the result back to the original representation. Note: The following bit order is assumed in the following discussions: bit-7 bit-6 bit-5 bit-4 bit-3 bit-2 bit-1 bit-0 MOST SIGNFICIANT BIT LEAST SIGNFICIANT BIT Some of the commonly use bit-wise operations are briefly described in the following subsections. Bit-wise NOT ( ~ ): The bit-wise NOT operator (~) is a unary operator and requires only 1 operand. It inverts all the bits in a given binary number. Here are a few examples of how the bit-wise NOT operator works: 1. Bit-wise NOT of 5 10 represented using 8-bit unsigned binary number representation is: a. 8-bit unsigned representation of 5 10 = 00000101 2. b. Bit-wise not of above number = 11111010 2. c. Interpreting above number as unsigned binary, result = 250 10. 2. Bit-wise not of -5 10 represented using 8-bit 2 s complement binary number representation is: a. 8-bit 2 s complement representation of -5 10 = 11111011 2. b. Bit-wise not of above number = 00000100 2. c. Interpreting above number as unsigned binary, result = 4 10. Page 10 of 14

Bit-wise AND ( & ) Bit-wise AND operator (&) is a binary operator and requires 2 binary numbers for operation. The two operands must have the same number of bits. Each bit from each operand are AND-ed together according to the truth table shown to the right to obtain the final result. Here is an example of how this operator works: A B A&B 0 0 0 0 1 0 1 0 0 1 1 1 1. Assume 8-bit 2 s complement representation of numbers. The bit wise and of 3 10 and -2 10 = a. The 8-bit 2 s complement representation of 3 10 = 00000011 2. b. The 8-bit 2 s complement representation of 2 10 = 11111110 2. c. Bit-wise AND of the above two binary numbers = 00000011 & 11111110 ------------ 00000010 ------------- d. Interpreting the above result (00000010 2 ) as a 8-bit 2 s complement number we get:: 2 10 e. Consequently 3 10 & -2 10 = 2 10. Bit-wise AND operation is often used to set bits in a number to 0 without affecting other bits. For this operation you need to create a suitable unsigned binary number, with appropriate bits set to 0 (all other bits set to 1) and bit-wise AND it with the given number. Here is an example to illustrate this concept. Using bit-wise AND, set bit-2 and bit-4 of 75 16 to 0 2 s without affecting other bits and show result of operation. a. In order to set bit-2 and bit-4 to 0 16, the value must be bit-wise AND-ed with: 11101011 2 (Note how only bit-2 and bit-4 are 0) b. 75 16 = 01110101 2 c. Result of bit wise AND: 01110101 2 & 11101011 2 = 01100001 = 61 16. Page 11 of 14

Bit-wise OR ( ) Bit-wise OR operator ( ) is a binary operator and requires 2 binary numbers for operation. The two operands must have the same number of bits. Each bit from each operand are OR-ed together according to the truth table shown to the right to obtain the final result. Here is an example of how this operator works: A B A B 0 0 0 0 1 1 1 0 1 1 1 1 2. Assume 8-bit 2 s complement representation of numbers. The bit wise OR of 3 10 and -2 10 = a. The 8-bit 2 s complement representation of 3 10 = 00000011 2. b. The 8-bit 2 s complement representation of -2 10 = 11111110 2. c. Bit-wise AND of the above two binary numbers = 00000011 11111110 ------------ 11111111 ------------- d. Interpreting the above result (11111111 2 ) as a 8-bit 2 s complement number we get:: -1 10 e. Consequently 3 10-2 10 = -1 10. Bit-wise OR operation is often used to set bits in a number to 1 without affecting other bits. For this operation you need to create a suitable unsigned binary number, with appropriate bits set to 1 and bit-wise OR it with X. Here is an example to illustrate this concept. Using bit-wise OR, set bit-2 and bit-4 of 61 16 to 1 2 s without affecting other bits and indicate result of operation. d. In order to set bit-2 and bit-4 to 1 16, the value must be bit-wise OR-ed with: 00010100 2 e. 61 16 = 01100001 2 f. Result of bit wise OR: 01100001 2 00010100 2 = 01110101 = 75 16. Page 12 of 14

Bit-wise XOR ( ^ ) Bit-wise XOR operator (^) is a binary operator and requires 2 binary numbers for operation. The two operands must have the same number of bits. Each bit from each operand are XOR-ed together according to the truth table shown to the right to obtain the final result. Here is an example of how this operator works: A B A^B 0 0 0 0 1 1 1 0 1 1 1 0 3. Assume 8-bit 2 s complement representation of numbers. The bit-wise XOR of 3 10 and -2 10 = a. The 8-bit 2 s complement representation of 3 10 = 00000011 2. b. The 8-bit 2 s complement representation of -2 10 = 11111110 2. c. Bit-wise AND of the above two binary numbers = 00000011 ^ 11111110 ------------ 11111101 ------------- d. Interpreting the above result (11111101 2 ) as a 8-bit 2 s complement number we get:: -3 10 e. Consequently 3 10 ^ -2 10 = -3 10. Page 13 of 14

7. Shift Operators Shift operations are one of the fastest operations supported by a microprocessor. They enable several mathematical operations and bit level manipulation of data. They are important and almost all high level programming languages include bit-wise operators in them. All of the shift operations share the following characteristics: Each operator works only with binary operand at a time. However, the shift operators require a second operand (a number) that indicates number of shifts to be performed. Shift operations are performed without paying heed to the actual representation of the binary number. However, the results from the operations are interpreted using the appropriate number representation. Shift operations do not change the size of the binary number. Given a non-binary number, you have to first convert it to binary (using suitable representation), perform the specified bit-wise operation, and then convert the result back to the original representation. The two shift operations that are supported by almost all microprocessors are briefly described in the following subsections. Shift Left ( << ) As the name suggests, the shift left operator shifts bits to the left (assuming the most significant bit is written first). Left most bits are lost and 0s are padded to the right to ensure that the result is of the same size as the source operand. Example of the shift left operator is shown below: 1. Assuming 8-bit 2 s complement representation, the result of shifting -2 10 to the left 3 times (written as: -2 10 << 3 10 ) is: a. The 8-bit 2 s complement representation of -2 10 = 11111110 2. b. Shifting above binary number to left 3 10 times we get: 11110000 2. c. Interpreting the above number as 8-bit 2 s complement we get: -16 10. Shift Right ( >> ) As the name suggests, the shift right operator (>>) shifts bits to the right (assuming the most significant bit is written first). Right most bits are lost and 0s are padded to the left to ensure that the result is of the same size as the source operand. Example of the shift right operator is shown below: 2. Assuming 8-bit 2 s complement representation, the result of shifting -2 10 to the left 3 times (written as: -2 10 << 3 10 ) is: a. The 8-bit 2 s complement representation of -2 10 = 11111110 2. b. Shifting above binary number to right 3 10 times we get: 00011111 2. c. Interpreting the above number as 8-bit 2 s complement we get: 31 10. Page 14 of 14