UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Number Systems and Bitwise Operation.

Slides:



Advertisements
Similar presentations
Intro to CS – Honors I Representing Numbers GEORGIOS PORTOKALIDIS
Advertisements

Company LOGO Edit your slogan here DKT 122/3 DIGITAL SYSTEM 1 WEEK #3 NUMBER SYSTEMS, OPERATION & CODES (PART 2)
ECE 331 – Digital System Design
CS 151 Digital Systems Design Lecture 3 More Number Systems.
ECE 331 – Digital System Design
Mathematics with Binary. Question  Below is a binary string  Which is the least significant bit (LSB)?  Which is the most significant bit (MSB)? 0.
Bit Operations C is well suited to system programming because it contains operators that can manipulate data at the bit level –Example: The Internet requires.
A bit can have one of two values: 0 or 1. The C language provides four operators that can be used to perform bitwise operations on the individual bits.
ENGIN112 L3: More Number Systems September 8, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 3 More Number Systems.
S. Barua – CPSC 240 CHAPTER 2 BITS, DATA TYPES, & OPERATIONS Topics to be covered are Number systems.
Chapter 1 Number Systems and Codes William Kleitz Digital Electronics with VHDL, Quartus® II Version Copyright ©2006 by Pearson Education, Inc. Upper Saddle.
Number Systems and Arithmetic
COE 202: Digital Logic Design Number Systems Part 1
Number Systems and Codes In PLC
Number Systems Lecture 02.
1 Lecture 2: Number Systems Binary numbers Base conversion Arithmetic Number systems  Sign and magnitude  Ones-complement  Twos-complement Binary-coded.
Converting binary to decimal decimal to binary
Revision Introductory Lesson
Computer Systems 1 Fundamentals of Computing Negative Binary.
Number Systems.
ES 244: Digital Logic Design Chapter 1 Chapter 1: Introduction Uchechukwu Ofoegbu Temple University.
ACOE1611 Data Representation and Numbering Systems Dr. Costas Kyriacou and Dr. Konstantinos Tatas.
Data Representation – Binary Numbers
1 Number SystemsLecture 8. 2 BINARY (BASE 2) numbers.
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
1 Homework Turn in HW2 tonight HW3 is on-line already Questions?
Information Representation. Digital Hardware Systems Digital Systems Digital vs. Analog Waveforms Analog: values vary over a broad range continuously.
Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved Binary Numbers Appendix.
Conversion of Number System Conversion Among Bases The possibilities: Hexadecimal DecimalOctal Binary
Number Systems. Today Decimal Hexadecimal Binary –Unsigned Binary –1’s Complement Binary –2’s Complement Binary.
Lecture 4 Last Lecture –Positional Numbering Systems –Converting Between Bases Today’s Topics –Signed Integer Representation Signed magnitude One’s complement.
Engineering 1040: Mechanisms & Electric Circuits Spring 2014 Number Systems.
Computer Number Systems. d n-1 d n-2 d n d 2-m d 1-m d -m Conventional Radix Number r is the radixd i is a digit d i Є {0, 1, ….., r – 1 } -m ≤
ECE 331 – Digital System Design
1 EENG 2710 Chapter 1 Number Systems and Codes. 2 Chapter 1 Homework 1.1c, 1.2c, 1.3c, 1.4e, 1.5e, 1.6c, 1.7e, 1.8a, 1.9a, 1.10b, 1.13a, 1.19.
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
Number systems, Operations, and Codes
Numbering System Base Conversion. Number systems Decimal – 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Binary – 0, 1 Octal – 0, 1, 2, 3, 4, 5, 6, 7 Hexadecimal system.
Positional Number Systems
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.
Number Systems Binary to Decimal Octal to Decimal Hexadecimal to Decimal Binary to Octal Binary to Hexadecimal Two’s Complement.
ECE 331 – Digital System Design Representation and Binary Arithmetic of Negative Numbers and Binary Codes (Lecture #10) The slides included herein were.
Octal to Decimal Hexadecimal DecimalOctal Binary.
Chapter 1  Number Systems Decimal System Binary System Octal System Hexadecimal System  Binary weighted cods Signed number binary order  1’s and 2’s.
AEEE2031 Data Representation and Numbering Systems.
ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included.
Binary01.ppt Decimal Decimal: Base 10 means 10 Unique numerical digits ,00010,000 Weight Positions 3,
Introduction to Microprocessors Chapter 2. Decimal or Base 10 Numbers  Have ten different digits (0-9)  It is a weighted number system. Each position.
WEEK #2 NUMBER SYSTEMS, OPERATION & CODES (PART 1)
Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.
Chapter 1 Number Systems Digital Electronics. Topics discussed in last lecture Digital systems Advantages of using digital signals over analog. Disadvantages.
0 Chap.2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations 2.5Arithmetic Operators 2.6Relational.
In decimal we are quite familiar with placing a “-” sign in front of a number to denote that it is negative The same is true for binary numbers a computer.
Number Representation 1 Lecture 2. Outcomes By the end of the session you should: – Understand what bits/bytes/words are. – Understanding conversion between.
CHAPTER 3 BINARY NUMBER SYSTEM. Computers are electronic machines which operate using binary logic. These devices use two different values to represent.
CPE 201 Digital Design Lecture 2: Digital Systems & Binary Numbers (2)
Number Systems and Codes
Octal to Decimal Decimal Octal Binary Hexadecimal.
CSE 102 Introduction to Computer Engineering
Location in course textbook
Number Systems and Bitwise Operation
Chapter 1 Number Systems & Conversions
TAO1221 COMPUTER ARCHITECTURE AND ORGANIZATION LAB 6
MMNSS COLLEGE,KOTTIYAM DEPARTMENT OF PHYSICS
Digital Electronics and Microprocessors
Homework Homework Continue Reading K&R Chapter 2 Questions?
Computer Architecture CST 250
1. Number Systems Chapt. 2.
Presentation transcript:

UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Number Systems and Bitwise Operation

UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming2 Binary, Octal, Hexadecimal, and Decimal Binary Binary numbering system has only two possible values for each digit: 0 and 1. For example, binary number decimal number

UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming3 Decimal Numbers Decimal The digits' weight increases by powers of 10. The weighted values for each position is determined as follows: For example, A decimal number 4261 can be thought of as follows. 4 * * * * 1 = = 4261 (decimal)

UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming4 Binary, Octal, Hexadecimal, and Decimal Binary The digits' weight increases by powers of 2. The weighted values for each position is determined as follows: For example, binary 10 is decimal 2. the binary value represents the decimal value * * * * * * * * 1 = = 202 (decimal)

UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming5 Binary Two’s Complement The left-most bit is the sign bit. If it is 1, then the number is negative. Otherwise, it is positive. Give a negative value, represent it in binary two’s complement form as follows. 1. write the number in its absolute value. 2. complement the binary number. 3. plus 1. Example, represent –2 in binary two’s complement with 16 bits for short int. Binary value of 2: 0b Binary complement of 2: 0b Plus 1: +1 Binary two’s complement representation of -2: 0b

UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming6 Give binary two’s complement form of a negative number, find the absolute value of the negative value as follows. 1. Complement the binary number. 2. Plus 1. Example, find the decimal value of (0b ) 2 in binary two’s complement form with 16 bits. Binary two’s complement (0b ) 2 Binary complement (0b ) 2 Plus 1 +1 Absolute value: (0b ) 2 = 2 10 Negative value: -2

UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming7 Subtraction of a value in the computer can be treated as addition of its two’s complement. For example, the subtraction of (2-2) can be performed as 2+(-2) as follows: 0b (binary representation of 2) 0b (two’s complement representation of -2) 0b (2+(-2))

UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming8 Example > short i, j > i = 0b > j = 0b > i+j 0

UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming9 Octal The octal system is based on the binary system with a 3-bit boundary. The octal number system uses base 8 includes 0 through 7. The weighted values for each position is as follows: Binary to Octal Conversion Break the binary number into 3-bit sections from the least significant bit (LSB) to the most significant bit (MSB). Convert the 3-bit binary number to its octal equivalent. For example, the binary value equals to octal value ( ) 8.

UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming10 2. Octal to Binary Conversion Convert the octal number to its 3-bit binary equivalent. Combine all the 3-bit sections. For example, the octal value equals to binary value Octal to Decimal Conversion To convert octal number to decimal number, multiply the value in each position by its octal weight and add each value together. For example, the octal value (167) 8 represents decimal value *64 + 6*8 + 7*1 = 119

UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming11 Hexadecimal Similar to octal, the hexadecimal system is also based on the binary system but using 4-bit boundary. The hexadecimal number system uses base 16 including the digits 0 through 9 and the letters A, B, C, D, E, and F. The letters A through F represent the decimal numbers 10 through 15. For the decimal values from 0 to 15, the corresponding hexadecimal values are listed below FEDCBA Decimal Hexadecimal

UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming12 The weighted values for each position is as follows: The conversion between binary value and hexadecimal value is similar to octal number,but using four-bit sections. The hexadecimal value 20A represents decimal value * * *1 = 522

UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming13 Following table provides all the information you need to convert from one type number into any other type number for the decimal values from 0 to16. BinaryOctalDecimalHexBinaryOctalDecimalHex A B C D E F

UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming14 Bitwise Operators There are six bitwise operators: OperatorNameDescription & bitwise AND The bit is set to 1 if the corresponding bits in the two operands are both 1. | bitwise OR The bit is set to 1 if at least one of the corresponding bits in the two operands is 1. ^ bitwise exclusive OR The bit is set to 1 if exactly one of the corresponding bits in the two operands is 1. << left shiftShift the bits of the first operand left by the number of bits specified by the second operand; fill from right with 0 bits. >> right shiftShift the bits of the first operand right by the number of bits specified by the second operand; filling from the left is implementation dependent. ~ One’s complement Set all 0 bits to 1, and all 1 bits to 0.

UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming15 Example: a b a & b a | b a ^ b b << a >> ~a

UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming16 /* File: bitop.ch (run in Ch only) Use Ch features “%b” and 0b */ #include int main() { char a = 0b ; char b = 0b ; char c; printf("a = 0b%8b\n", a); printf("b = 0b%8b\n", b); c = a & b; printf("a & b = 0b%8b\n", c); c = a | b; printf("a | b = 0b%8b\n", c); c = a ^ b; printf("a ^ b = 0b%8b\n", c); c = b << 1; printf("b << 1 = 0b%8b\n", c); c = a >> 1; printf("a >> 1 = 0b%8b\n", c); c = ~a; printf("~a = 0b%8b\n", c); return 0; } Output: a = 0b b = 0b a & b = 0b a | b = 0b a ^ b = 0b b << 1 = 0b a >> 1 = 0b ~a = 0b

UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming17 Logic Operators There are four logic operators: 1) ! --- logic NOT 2) && --- logic AND 3) || --- inclusive OR 4) ^^ --- exclusive OR (available in Ch only) a b !a a && b a || b a ^^ b

UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming18 End Number Systems and Bitwise Operation Q & A!