Copyright (c) 2004 Professor Keith W. Noe Number System & Codes Number Conversions Part II.
Number system part 1
-
Upload
excel-technology-lanka-pvt-ltd -
Category
Education
-
view
138 -
download
0
description
Transcript of Number system part 1
![Page 1: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/1.jpg)
NUMBER SYSTEMPart 1
![Page 2: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/2.jpg)
Objectives - To understand3.1 Analyses how numeric data are
represented in computers
I. Decimal representation of numbers (Signed and Unsigned)
II. Integers III. Fixed Point and Floating-Point numbers IV. Number systems used in computing
Binary, Octal, Hexa-decimal logic operationV. Conversions among number systems
![Page 3: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/3.jpg)
Introduction
![Page 4: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/4.jpg)
Introduction
A number system defines a set of values used to represent a quantity.
The study of numbers is not only related to computers. We apply numbers everyday, and knowing how numbers work, will give us an insight of how computers manipulate and store numbers.
A number is a mathematical object used in counting and measuring. It is used in counting and measuring. Numerals are often used for labels, for ordering serial numbers, and for codes like ISBNs. In mathematics, the definition of number has been extended over the years to include such numbers as zero, Positive numbers , Negative numbers , Integers numbers , Rational numbers, Irrational numbers, Whole number and complex numbers.
Certain procedures which take one or more numbers as input and produce a number as output are called numerical operation.
![Page 5: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/5.jpg)
Complex number:- The complex numbers consist of all numbers of the form (a+bi) ; Where a and b are real numbers and i=0.1
Ex :- 2+5i , 3+3i , … . .. . . . , 14+20i
Real Numbers (R) :- The real numbers include all of the measuring numbers
Ex :- -69 , -2 , -1.5 , +5 …+ 7.5 . .. . . . , +14
Rational Numbers (Q) :- A rational number is a number that can be expressed as a fraction with an integer and a non-zero natural number denominator Ex :- -25 , -15/10 , 0 , 0.05 , 0.2 , 7/3 , 25 ,36
Irrational Numbers:- A decimal that can be written as a fraction either ends (terminates)or forever repeats about which we will see in detail further.
Ex – π =3.14159365358979
Natural numbers (N) :-All positive numbers (Counting numbers) started with 1.However in the 19th century, mathematicians started including 0 in the set of natural
numbers.
Ex :- 0,1,2,3,4,……,55 ,105 . .. . . .
Types of numbers
![Page 6: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/6.jpg)
Types of numbers
Integers (Z):- Integers are the number which includes positive and negative numbers. Negative numbers are usually written with a negative sign (also called a minus sign)in front of the number they are opposite of .When the set of negative numbers is combined with the natural numbers zero, the result is the set of integer numbers
Ex :- -25 , -15 , +0 , +25 , +36
Fractions :- This is a type of a rational number. Fractions are written as two numbers (m/n), the numerator (m) and the denominator(n)
1. Fixed point Number2.Floating point number
![Page 7: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/7.jpg)
Fixed point number :-Involving or being a mathematical notation(as in a decimal
system) in which the point separating whole numbers and fractions is
fixed
A fixed point number has a specific number of bits (or digits) reserved
for the integer part (the part to the left of the decimal point) and a
specific number of bits reserved for the fractional part (the part tothe
right of the decimal point). No matter how large or small your number is, it will always use the same number of bits for each portion.
For example:- if your fixed point format was in decimal IIIII.FFFFF then the largest number you could represent would be 99999.99999 and the smallest would be 00000.00001. Every bit of code that processes such numbers has to have built-in knowledge of where the decimal point is.
123.5625.238955.30.50.0098
A fixed point number just means that there are a fixed number of digits after the decimal point.
![Page 8: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/8.jpg)
Floating point number :-A floating point number does not reserve a specific number of bits for the
integer part or the fractional part. Instead it reserves a certain number of bits for the number
(called the mantissa or significant) and a certain number of bits to say where within that number the decimal place sits (called the exponent).
For example:-So a floating point number that took up 10 digits with 2 digits reserved for the exponent might represent a largest value of
9.9999999e+50 and a smallest value of 0.0000001e-49.
1.2 × 102
35.02 × 1080
0.258 × 10-14 / 2.58 × 10-15 / 25.8 × 10-16
A floating point number allows for a varying number of digits after the decimal point.
![Page 9: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/9.jpg)
Types of numbers
![Page 10: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/10.jpg)
![Page 11: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/11.jpg)
Precision({Í ý<) and Accuracy (ùÚØ<÷À]õ$<)
•Precision is the measure of how closely individual measurements agree with one another.
• Accuracy is how closely individual measurements with the correct value.
![Page 12: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/12.jpg)
![Page 13: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/13.jpg)
Significant Digits(µ<µ&&Ú &‘ç]$‘æ×) "Significant Digits", also called "Significant Digits of Precision", are the digits in a number starting with the first non-zero digit and ending with the last non-zero digit. Those digits can be anywhere relative to the decimal.
Non-zero digits are always significant.
22 has two significant digits,22.3 has three significant digits.
With zeroes, the situation is more complicated
a. Zeroes placed before other digits are not significant; 0.046 has two significant digits.
b. Zeroes placed between other digits are always significant; 4009 kg has four significant digits.
c. Zeroes placed after other digits but behind a decimal point are significant;
7.90 has three significant digits. 85.00 g has four significant digits9.000 000 000 mm has 10 significant digits
![Page 14: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/14.jpg)
Significant Digits
d. Zeros at the end of a number but to the left of a decimal may or may not be significant. If such a zero has been measured, or is the first estimated digit, it is significant. On the other hand, if the zero has not been measured or estimated but is just a placeholder, it is not significant. A decimal placed after the zeros indicates that they are significant
1. 2000 m may contain from one to four significant digits, depending on how many zeros are placeholders. For measurements given in this text , assume that 2000 has one significant digits.
2. 2000. m contains four significant digits, indicated by the presence of the decimal point
3.1000.0 has five significant digits (the ".0" tells us something interesting about the presumed accuracy of the measurement being made: that the measurement is accurate to the tenths place, but that there happen to be zero tenths)
For example:- in the number 8200, it is not clear if the zeroes are significant or not. The number of significant digits in 8200 is at least two, but could be three or four. To avoid uncertainty, use scientific notation to place significant zeroes behind a decimal point:i.8.200 *103 has four significant digits ii.8.20 *103 has three significant digits iii.8.2 *103 has two significant digits
![Page 15: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/15.jpg)
![Page 16: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/16.jpg)
![Page 17: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/17.jpg)
![Page 18: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/18.jpg)
![Page 19: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/19.jpg)
![Page 20: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/20.jpg)
![Page 21: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/21.jpg)
![Page 22: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/22.jpg)
Significant Digits
Scientific notation - All digits expressed before the exponential term are significant.
5.060 x 10-3 m has four sig figs.
9.00 x 102 g has three sig figs.
![Page 23: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/23.jpg)
Significant DigitMost Significant Digit
•The MSD in a number is the digit that has the greatest effect on that number. Highest power of base weightingThe digits on the left hand side are called the high-order digits (higher powers of 10)
Least Significant Digit (MSD and LSD)• The LSD in a number is the digit that has the least effect on that number.• Lowest power of base weighting• Digits on the right hand side are called the low-order digits (lower powers of 10).
![Page 24: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/24.jpg)
Significant Digit
You can easily see that a change in the MSD will increase or decrease the value of the number the greatest amount. Changes in the LSD will have the smallest effect on the value. The nonzero digit of a number that is the farthest LEFT is the MSD, and the nonzero digit farthest RIGHT is the LSD, as in the following example
![Page 25: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/25.jpg)
Key principle of numbering systems
Radix point (´ÕÙæ ÙæßÂ]× ) Divides fractional portion from the whole portion of a number
Weighting Factor (ýØ &$øæ× ) A multiplier value is used in each column position of a number. It represents the weight factor. Its value determines how many times the Base value is multiplied by itself thus giving the placeholders seen below from right to left labelled as "Ones", "Tens", "Hundreds", "Thousands", "Ten Thousands" and so on. . .
![Page 26: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/26.jpg)
POSITIONAL (&ßö$ùÛ×)NUMBER SYSTEMS
In a positional number system, the position a symbol occupies in the number determines the value it represents. In this system, a number represented as:
In our decimal number system, the value of a digit depends on its place, or position, in the number. Each place has a value of 10 times the place to its right.A number in standard form is separated into groups of three digits using commas. Each of these groups is called a period.
![Page 27: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/27.jpg)
POSITIONAL (&ßö$ùÛ×)NUMBER SYSTEMS
![Page 28: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/28.jpg)
POSITIONAL (&ßö$ùÛ×)NUMBER SYSTEMS
![Page 29: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/29.jpg)
POSITIONAL (&ßö$ùÛ×)NUMBER SYSTEMS
In a positional number system, the position a symbol occupies in the number determines the value it represents. In this system, a number represented as:
has the value of:
in which S is the set of symbols, b is the base (or radix).
![Page 30: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/30.jpg)
Key principle of numbering systems
Positional value significanceGives weight each digit contributes to the number’s overall value
Ex:-1.Steps for base 10Determine positional value of each digit by raising 10 to
position within number2. Steps for base 2 Determine positional value of each digit by raising 2 to position
within number
![Page 31: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/31.jpg)
General procedure (any base) Calculate position value of the number by raising the base value to
the power of the position Multiply positional value by digit in that position Add each calculated value together
Calculate Position Value and Weighed
![Page 32: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/32.jpg)
Number RepresentationsInteger numbers are those numbers which do not have fractional parts. Integer numbers include both positive numbers and negative numbers. They can be handled using any of the following representations
Unsigned notationSigned magnitude notion
![Page 33: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/33.jpg)
Unsigned notation
An unsigned integer is an integer that can never be negative and can take only 0 or positive values. Its range is between 0 and positive infinity. All unsigned numbers are Positive
0 , 1 , 2 , 3 , 4 , . . . . , 1598 , . . . .
Range = 0 to (2n – 1) ; n is the number of bits used to store the unsigned integer.
Numbers with values GREATER than (2n – 1) would require more bits. If you try to store too large a value without using more bits, OVERFLOW will occur.
Example: On a system that stores unsigned integers in 16-bit words: Range = 0 to (216 – 1) = 0 to 65535
Therefore, you cannot store numbers larger than 65535 in 16 bits.
![Page 34: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/34.jpg)
Advantages: 1.One representation of zero
2.Simple addition
Disadvantages : 1.Negative numbers can not be represented.
2.The need of different notation to represent negative numbers.
Unsigned representation
![Page 35: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/35.jpg)
Signed notation Until now we've been concentrating on unsigned numbers. In real life we
also need to be able represent signed numbers (like : -12, -45, +78).
A signed number MUST have a sign (+/-). A method is needed to represent the sign as part of the binary representation. All signed numbers are negative and positive
-1.5 103 , - 25 , -9.610-4 , +0 , +5.710-4 , +0.5 , +98 , +4.6 103
Range =-(2(n-1) – 1) to +(2(n-1) – 1) ; n is the number of bits used to store the sign/magnitude integer
Numbers with values GREATER than +(2(n-1) – 1) and values LESS than -(2(n-1) – 1) would require more bits. If you try to store too large/too small a value without using more bits, OVERFLOW will occur.
Example: On a system that stores unsigned integers in 16-bit words: Range = -(2(16-1) – 1) to +(2(16-1) – 1) = -(2(15) – 1) to +(2(15) – 1)
= -32767 to +32767 Therefore, you cannot store numbers larger than 32767 or smaller than -32767 in 16 bits.
![Page 36: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/36.jpg)
Advantages:Represents positive and negative numbers
Disadvantage : Arithmetic operations are difficult.
Addition and subtractions are difficult.Signs and magnitude, both have to carry out the required operation.They are two representations of 0 (Binary number system)
00000000 = + 010
10000000 = - 010
To test if a number is 0 or not, the CPU will need to see whether it is 00000000 or 10000000.0 is always performed in programs.
Therefore, having two representations of 0 is inconvenient.
Sign Representation
![Page 37: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/37.jpg)
Summary No. of bits
Binary
Unsigned Sign-magnitude
Min Max Min Max
1 0 1
2 0 3 -1 1
3 0 7 -3 3
4 0 15 -7 7
5 0 31 -15 15
6 0 63 -31 31
Etc.
No. of bits
Binary
Unsigned Sign-magnitude
Min Max Min Max
n 0 2n - 1 -(2
n-1 – 1) 2n-1 - 1
![Page 38: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/38.jpg)
Numeric
Representations
![Page 39: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/39.jpg)
Numbering Systems
Integer ……………. Z Decimal …………… Base 10 (N10) Binary …………….. Base 2 (N2) Octal ………………. Base 8 (N8) Hexadecimal ……. Base 16 (N16)
![Page 40: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/40.jpg)
Integer
![Page 41: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/41.jpg)
Integer
A number with no fractional part Includes the counting numbers {1, 2, 3, ...}, zero {0}, and the negative of the counting numbers {-1, -2, -3, ...}
You can write them down like this: {..., -3, -2, -1, 0, 1, 2, 3, ...}
Examples of integers: -16, -3, 0, 1, 198
![Page 42: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/42.jpg)
Decimal
![Page 43: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/43.jpg)
Decimal Number System The decimal system is a base-10 system. There are 10 distinct digits (0 to 9) to represent any
quantity.
10 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
For an n-digit number, the value that each digit represents depends on its weight or position.
Digit Position
Integer & fraction 123.456
The weights are based on powers of 10.
Weight = (Base) Position
1024 = 1*103 + 0*102 + 2*101 + 4*100 = 1000 + 20 + 4
Positional value example: 436.95To the left of the radix point : 4 in position two / 3 in position one / 6 in position zeroTo the right of the radix point: 9 in position negative one / 5 in position negative two
![Page 44: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/44.jpg)
Decimal Number System
Base (also called radix) = 10 10 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
Digit Position Integer & fraction
Digit Weight Weight = (Base) Position
Magnitude Sum of “Digit x Weight”
Formal Notation
1 0 -12 -2
5 1 2 7 4
10 1 0.1100 0.01
500 10 2 0.7 0.04
d2*B2+d1*B
1+d0*B0+d-1*B
-1+d-2*B-2
(512.74)10
![Page 45: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/45.jpg)
Example
For D = 52.946
![Page 46: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/46.jpg)
Uses the ten numbers from 0 to 9Each column represents a power of 10
Fixed-point representation
Uses the two numbers from 0 to 9Every column represents a power of 10
Standard decimal representation
![Page 47: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/47.jpg)
Positional values for a base 10 number
Positional Value (cont’d.)
![Page 48: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/48.jpg)
Whole Numbers (Radix = 10):
123410 = 1 103 + 2 102 + 3 101 + 4 100
With Fractional Part (Radix = 10):
36.7210 = 3 101 + 6 100 + 7 10-1 + 2 10-2
General Case (Radix = R):
(S1S0.S-1S-2)R =S1 R1 + S0 R0 + S-1 R -1 + S-2 R-2
Reals
![Page 49: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/49.jpg)
Practice (base 10) (Scientific notation )
1) 258 = 2.58 x 102
Mantissa = 258Radix = 10Exponent = 2
3) One billion=1,000,000,000 =1 x 109
significand or mantissa: 1 base or radix: 10 exponent: 9
2) The following shows the place values for the integer +224 in the The following shows the place values for the integer +224 in the decimal system.decimal system.
Note that the digit 2 in position 1 has the value 20, but the same digit in position 2 has the value 200. Also note that we normally drop the plus sign, but it is implicit.
4) 1999 =1.999 x 103
significand or mantissa: 1999 base or radix: 10exponent: 3
=19.99 x 102
=199.9 x 1012) 24.25 = 2.425 x 101
=Mantissa = 2425=Radix = 10=Exponent = 1
![Page 50: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/50.jpg)
The following shows the place values for the decimal number −7508. We have used 1, 10, 100, and 1000 instead of powers of 10.
Example
( ) Values
Note that the digit 2 in position 1 has the value 20, but the same digit in position 2 has the value 200. Also note that we normally drop the plus sign, but it is implicit.
ExampleThe following shows the place values for the real number +24.13.
![Page 51: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/51.jpg)
Binary
![Page 52: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/52.jpg)
Binary Number Systems The binary system is a base-2 system. There are 2 distinct digits (0 and 1) to represent any quantity.
2 digits { 0, 1 }, called binary digits or “bits”
For an n-digit number, the value of a digit in each column depends on its position.
The weights are based on powers of 2. Weight = (Base) Position
10112 = 1*23 + 0*22 + 1*21 + 1*20 =8+2+1 =1110
• 0 = represents no value
• 1 = represents a unit value
![Page 53: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/53.jpg)
Binary Number System Weights
Weight = (Base) Position
MagnitudeSum of “Bit x Weight”
Formal Notation Groups of bits 4 bits = Nibble
8 bits = Byte
1 0 -12 -2
2 1 1/24 1/4
1 0 1 0 1
=1 *22+0 *21+1 *20+0 *2-1+1 *2-2
=(5.25)10
=(101.01)2
1 0 1 1
1 1 0 0 0 1 0 1
![Page 54: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/54.jpg)
Binary Number SystemBinary number Value encoded by the binary number
0 0×20 = 0
1 1×20 = 1
10 1×21 + 0 ×20 = 2
11 1×21 + 1 ×20 = 3
1010 1×23 + 0×22 + 1×21 + 0×20 = 8 + 2 = 10
Base-2 scientific notation1) 2.25ten = 10.01two = 10.01two x 20 = 1.001two x 21 normalized Numbers are usually normalized which means that the leading bit is always a 1.
Digit 1 1 0 0 . 1 0 1
Weight
23 22 21 20 Binary decimal Point
2-
1 2-2 2-3
2) 1100.101two
![Page 55: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/55.jpg)
Standard binary representationUses the two numbers from 0 to 1Every column represents a power of 2
Fixed-point representation
Uses the two numbers from 0 to 1Every column represents a power of 2
![Page 56: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/56.jpg)
Positional Value1)Positional value of the binary number 10112
Rightmost position: positional value of the base (2) raised to the 0 power
First Positional value: 1 (1 * 20) Next position: value of 2 raised to the power of 1 (1 * 21) Next position: 2 squared (0 * 22) Next position: 2 to the third (1 * 23)
(1 * 20) + (1 * 21) + (0 * 22) + (1 * 23)2)Positional value of the binary number 1011.0112 as follows
![Page 57: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/57.jpg)
![Page 58: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/58.jpg)
Whole Numbers (Radix = 2):
10112 = 1 23 + 0 22 + 1 21 + 1 20
With Fractional Part (Radix = 2):
11.012 = 1 21 + 1 20 + 0 2-1 + 1 2-2
General Case (Radix = R):
(S1S0.S-1S-2)R =S1 R1 + S0 R0 + S-1 R -1 + S-2 R-2
Real's
![Page 59: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/59.jpg)
Example
The following shows that the number (11001)2 in binary is the same as 25 in decimal. The subscript 2 shows that the base is 2.
The equivalent decimal number is N = 16 + 8 + 0 + 0 + 1 = 25.
Example The following shows that the number (101.11)2 in binary is equal to the number 5.75 in decimal.
![Page 60: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/60.jpg)
Octal
![Page 61: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/61.jpg)
Octal Number Systems Octal and hexadecimal systems provide a shorthand way to deal
with the long strings of 1’s and 0’s in binary.
Octal is base-8 system using the digits 0 to 7.
8 digits { 0, 1, 2, 3, 4, 5, 6, 7 }
To convert to decimal, you can again use a column weighted system
Weight = (Base) Position
75128 = 7*83 + 5*82 + 1*81 + 2*80 = 391410
An octal number can easily be converted to binary by replacing each octal digit with the corresponding group of 3 binary digits
75128 = 1111010010102
![Page 62: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/62.jpg)
Octal Number System
WeightsWeight = (Base) Position
MagnitudeSum of “Digit x Weight”
Formal Notation
1 0 -12 -2
8 1 1/864 1/64
5 1 2 7 4
5 *82+1 *81+2 *80+7 *8-1+4 *8-2
=(330.9375)10
=(512.74)8
![Page 63: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/63.jpg)
Place values for an integer in the octal system
Real's
![Page 64: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/64.jpg)
Binary Decimal Octal
0 0 0
1 1 1
10 2 2
11 3 3
100 4 4
101 5 5
110 6 6
111 7 7
Octal Number System
Octal is used as a shorthand for representing file permissions on UNIX systems. For example, file mode rwxr-xr-x would be 0755.
![Page 65: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/65.jpg)
Example
The following shows that the number (1256)8 in octal is the same as 686 in decimal.
Note that the decimal number is N = 512 + 128 + 40 + 6 = 686.
The weight associated with each digit in the given octal number can be determined by raising 8 to a power equivalent to the position of the digit in the number.
Example
![Page 66: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/66.jpg)
Hexadecimal
![Page 67: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/67.jpg)
Number Systems - Hexadecimal Hexadecimal is a base-16 system.
It contains the digits 0 to 9 and the letters A to F (16 digit values).
16 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F }
Note :- symbols A, B, C, D, E, F are equal to 10, 11, 12, 13, 14, 15 respectively. The symbols in this system are often referred to as hexadecimal digits
The letters A to F represent the unit values 10 to 15.
This system is often used in programming as a condensed form for binary numbers (0x00FF, 00FF)
To convert to decimal, use a weighted system with powers of 16. Conversion to binary is done the same way as octal to
binary conversions. This time though the binary digits are organized into groups
of 4. Conversion from binary to hexadecimal involves breaking
the bits into groups of 4 and replacing them with the hexadecimal equivalent.
![Page 68: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/68.jpg)
Hexadecimal Number System
Weights Weight = (Base) Position
Magnitude Sum of “Digit x Weight”
Formal Notation
1 0 -12 -2
16 1 1/16256 1/256
1 E 5 7 A
1 *162+14 *161+5 *160+7 *16-1+10 *16-2
=(485.4765625)10
=(1E5.7A)16
![Page 69: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/69.jpg)
Integers
Place values for an integer in the hexadecimal system
![Page 70: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/70.jpg)
The Hexadecimal Number SystemBinary Decimal Hexadecimal Binary Decimal Hexadecimal 0 0 0 1000 8 8
1 1 1 1001 9 9 10 2 2 1010 10 A 11 3 3 1011 11 B 100 4 4 1100 12 C 101 5 5 1101 13 D 110 6 6 1110 14 E 111 7 7 1111 15 F
Example of a hexadecimal number and the values of the positions 3 C 8 B 0 5 1 166 165 164 163 162 161 160
![Page 71: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/71.jpg)
Hexadecimal SystemThe weight associated with each symbol in the given hexadecimal
number canbe determined by raising 16 to a power equivalent to the position of
the digit inthe number.
Digit 4 A 9 0 . 2 B C
Weight
163 162 161 160 Hexadecimal Point 16-1 16-2 16-3
4A90.2BCExample
The following shows that the number (2AE)16 in hexadecimal is equivalent to 686 in decimal.
The equivalent decimal number is N = 512 + 160 + 14 = 686.
Example
![Page 72: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/72.jpg)
Value of 2001 in Binary, Octal and HexadecimalHexadecimal System
![Page 73: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/73.jpg)
Hexadecimal System
![Page 74: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/74.jpg)
Summary of the four positional systems
![Page 75: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/75.jpg)
1).Why do we use the decimal system for everyday mathematics?
Answer: Fingers and Thumbs
2).Why do we use the binary system for computer mathematics?
Answer: Computers use voltage levels to perform mathematics.
0-Volts and 5-Volts correspond to 0’s and 1’s
![Page 76: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/76.jpg)
Common PowersBase 10
Power Preface Symbol
10-12 pico p
10-9 nano n
10-6 micro
10-3 milli m
103 kilo k
106 mega M
109 giga G
1012 tera T
Value
.000000000001
.000000001
.000001
.001
1000
1000000
1000000000
1000000000000
![Page 77: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/77.jpg)
Common Powers Base 2
Power Preface Symbol
210 kilo k
220 mega M
230 Giga G
Value
1024
1048576
1073741824
• What is the value of “k”, “M”, and “G”?• In computing, particularly w.r.t. memory, the base-2 interpretation generally applies
![Page 78: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/78.jpg)
Converting Numbers Between
Bases
![Page 79: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/79.jpg)
Conversion Among Bases
The possibilities
Hexadecimal
Decimal Octal
Binary
![Page 80: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/80.jpg)
Converting Numbers Between Bases Can represent any quantity in any base
Counting process similar for all bases Count until highest digit for base reached Add 1 to next higher position to left Return to 0 in current position
Conversion: map from one base to another Identities easily calculated Identities obtained by table lookup
![Page 81: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/81.jpg)
Decimal to Decimal
Hexadecimal
Decimal Octal
Binary
![Page 82: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/82.jpg)
12510 => 5 x 100 = 52 x 101 = 201 x 102 = 100
125
Base
Weight
Example
![Page 83: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/83.jpg)
Decimal to Binary
Hexadecimal
Decimal Octal
Binary
![Page 84: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/84.jpg)
Converting From Decimal to Binary
• Make a list of the binary place values up to the number being converted.
• Perform successive divisions by 2, placing the remainder of 0 or 1 in each of the positions from right to left.
• Continue until the quotient is zero.
• Example: 4210
25 24 23 22 21 20
32 16 8 4 2 1 1 0 1 0 1 0
![Page 85: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/85.jpg)
12510 = ?22 125 62 12 31 02 15 12 7 12 3 12 1 12 0 1
12510 = 11111012
Example
![Page 86: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/86.jpg)
Decimal to Binary 149210 (decimal) = ???2 (binary)
Repeated Divide by 2
Example
![Page 87: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/87.jpg)
ExampleThe following shows how to convert 35 in decimal to binary. We start with the number in decimal, we move to the left while continuously finding the quotients and the remainder of division by 2. The result is 35 = (100011)2.
Example
Convert the decimal number 0.625 to binary.
Since the number 0.625 = (0.101)2 has no integral part, the example shows how the fractional part is calculated.
![Page 88: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/88.jpg)
Decimal (Fraction) to Binary Conversion
Multiply the number by the ‘Base’ (=2) Take the integer (either 0 or 1) as a coefficient Take the resultant fraction and repeat the division
Example: (0.625)10
Integer Fraction Coefficient
Answer: (0.625)10 = (0.a-1 a-2 a-3)2 = (0.101)2
MSB LSBMSB LSB
0.625 * 2 = 1 . 25 a-1 = 10.25 * 2 = 0 . 5 a-2 = 00.5 * 2 = 1 . 0 a-3 = 1
![Page 89: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/89.jpg)
![Page 90: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/90.jpg)
Example
A similar method can be used to convert a decimal fraction to binary when the denominator is a power of two:
The answer is then (0.011011)The answer is then (0.011011)22
![Page 91: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/91.jpg)
ExampleAn alternative method for converting a small decimal integer (usually less than 256) to binary is to break the number as the sum of numbers that are equivalent to the binary place values shown:
![Page 92: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/92.jpg)
Binary to Decimal
Hexadecimal
Decimal Octal
Binary
![Page 93: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/93.jpg)
Binary to Decimal Technique
Multiply each bit by 2n, where n is the “weight” of the bit
The weight is the position of the bit, starting from 0 on the right
Add the results
![Page 94: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/94.jpg)
Converting from Binary to Decimal
Example
Example
![Page 95: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/95.jpg)
1010112 => 1 x 20 = 11 x 21 = 20 x 22 = 01 x 23 = 80 x 24 = 01 x 25 = 32
4310
Bit “0”
Example
![Page 96: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/96.jpg)
Example
The following shows how to convert the binary The following shows how to convert the binary number (110.11)number (110.11)22 to decimal: (110.11) to decimal: (110.11)22 = 6.75. = 6.75.
![Page 97: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/97.jpg)
Decimal to Octal
Hexadecimal
Decimal Octal
Binary
![Page 98: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/98.jpg)
123410 = ?8
8 1234 154 28 19 28 2 38 0 2
123410 = 23228
Example
![Page 99: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/99.jpg)
Decimal to Octal Conversion
(175)10
Quotient Remainder Coefficient
Answer: (175)10 = (a2 a1 a0)8 = (257)8
175 / 8 = 21 7 a0 = 7 21 / 8 = 2 5 a1 = 5 2 / 8 = 0 2 a2 = 2
(0.3125)10Integer Fraction Coefficient
Answer: (0.3125)10 = (0.a-1 a-2 a-3)8 = (0.24)8
0.3125 * 8 = 2 . 50.5 * 8 = 4 . 0 a-2 = 4
a-1 = 2
Example
Example
![Page 100: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/100.jpg)
ExampleThe following shows how to convert 126 in decimal to its equivalent in the octal system. We move to the right while continuously finding the quotients and the remainder of division by 8. The result is 126 = (176)8.
Example
The following shows how to convert 0.634 to octal using a maximum of four digits. The result is 0.634 = (0.5044)8. Note that we multiple by 8 (base octal).
![Page 101: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/101.jpg)
Octal to Decimal
Hexadecimal
Decimal Octal
Binary
![Page 102: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/102.jpg)
Octal to Decimal Technique
Multiply each bit by 8n, where n is the “weight” of the bit
The weight is the position of the bit, starting from 0 on the right
Add the results
86 85 84 83 82 81 80
26214410 3276810 409610 51210 6410 810 110
![Page 103: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/103.jpg)
Example
The following shows how to convert (724)8 to decimal.
The following shows how to convert (23.17)8 to decimal.
This means that (23.17)8 ≈ 19.234 in decimal. Again, we have rounded up 7 × 8−2 = 0.109375.
Example
![Page 104: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/104.jpg)
Decimal to Hexadecimal
Hexadecimal
Decimal Octal
Binary
![Page 105: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/105.jpg)
123410 = ?16
123410 = 4D216
16 1234 77 216 4 13 = D16 0 4
Example
![Page 106: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/106.jpg)
ExampleThe following shows how we convert 126 in decimal to its equivalent in the hexadecimal system. We move to the right while continuously finding the quotients and the remainder of division by 16. The result is 126 = (7E)16
The following shows how to convert 178.6 in decimal to hexadecimal using only one digit to the right of the decimal point. The result is 178.6 = (B2.9)16 Note that we divide or multiple by 16 (base hexadecimal).
Example
![Page 107: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/107.jpg)
Hexadecimal to Decimal
Hexadecimal
Decimal Octal
Binary
![Page 108: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/108.jpg)
Hexadecimal to Decimal Technique
Multiply each bit by 16n, where n is the “weight” of the bit
The weight is the position of the bit, starting from 0 on the right
Add the results
165 164 163 162 161 160
104857610 6553610 409610 25610 1610 110
![Page 109: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/109.jpg)
ABC16 => C x 160 = 12 x 1 = 12 B x 161 = 11 x 16 = 176 A x 162 = 10 x 256 = 2560
274810
Example
The following shows how to convert the hexadecimal number (ABC)16 to decimal.
ExampleThe following shows how to convert the hexadecimal number (1A.23)16 to decimal.
Note :- The result in the decimal notation is not exact, because Note :- The result in the decimal notation is not exact, because 3 × 16 3 × 16−2−2 = 0.01171875. We have rounded this value to = 0.01171875. We have rounded this value to threethree digits (0.012). digits (0.012).
![Page 110: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/110.jpg)
Base N to Decimal conversion
Decimal to Base N Conversions To convert from decimal to a different number base such as Octal, Binary or Hexadecimal involves repeated division by that number base
Keep dividing until the quotient is zero Use the remainders in reverse order as the digits of the
converted number
![Page 111: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/111.jpg)
Binary to Octal
Hexadecimal
Decimal Octal
Binary
![Page 112: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/112.jpg)
Binary-octal conversion8 = 23
Each group of 3 bits represents an octal digit
Group bits in threes, starting on right Convert to octal digits
![Page 113: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/113.jpg)
Binary − Octal Conversion
Octal Binary
0 0 0 0
1 0 0 1
2 0 1 0
3 0 1 1
4 1 0 0
5 1 0 1
6 1 1 0
7 1 1 1
( 1 0 1 1 0 . 0 1 )2
( 2 6 . 2 )8
Assume Zeros
Works both ways (Binary to Octal & Octal to Binary)
10110101112 = ?81 011 010 111
1 3 2 7
10110101112 = 13278
Example
Example
![Page 114: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/114.jpg)
Example
Show the octal equivalent of the binary number (101110010)2.
SolutionEach group of three bits is translated into one octal digit. The equivalent of each 3-bit group is shown in Table on above page
(101110010)2 = (562)8.
101 110 010
Example
What is the binary equivalent of for (24)8?
SolutionWrite each octal digit as its equivalent bit pattern to get
2 → 010 and 4 → 100
The result is (010100)2.
![Page 115: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/115.jpg)
Octal to Binary
Hexadecimal
Decimal Octal
Binary
![Page 116: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/116.jpg)
Octal to Binary• Technique
• Convert each octal digit to a 3-bit equivalent binary representation
• Useful to represent binary numbers indirectlyOctal and binary are nicely related; i.e. 8 = 23
Each octal digit represent 3 binary digits (bits)
7058 = ?2
7 0 5
111 000 101
7058 = 1110001012
Example
![Page 117: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/117.jpg)
Binary to Hexadecimal
Hexadecimal
Decimal Octal
Binary
![Page 118: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/118.jpg)
Binary-hexadecimal conversion
Technique
Group bits in fours, starting on rightConvert to hexadecimal digits
![Page 119: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/119.jpg)
Binary − Hexadecimal Conversion
16 = 24
Each group of 4 bits represents a hexadecimal digit
Example:
( 1 0 1 1 0 . 0 1 )2
( 1 6 . 4 )16
Assume Zeros
Works both ways (Binary to Hex & Hex to Binary)
![Page 120: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/120.jpg)
![Page 121: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/121.jpg)
Example
Show the hexadecimal equivalent of the binary number (110011100010)2.
SolutionSolutionWe first arrange the binary number in 4-bit patterns:We first arrange the binary number in 4-bit patterns:
1100 1110 00101100 1110 0010Note that the leftmost pattern can have one to four bits. We then use the equivalent of each pattern shown in Table 2.2 on page 25 to change the number to hexadecimal: (4E2)16.Example
![Page 122: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/122.jpg)
Hexadecimal to Binary
Hexadecimal
Decimal Octal
Binary
![Page 123: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/123.jpg)
Hexadecimal to Binary Technique
Convert each hexadecimal digit to a 4-bit equivalent binary representation
Useful to represent binary numbers indirectly Hex and binary are nicely related; i.e. 16 =
24
Each hex digit represent 4 binary digits (bits)
![Page 124: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/124.jpg)
10AF16 = ?2
1 0 A F
0001 0000 1010 1111
10AF16 = 00010000101011112
Example
Example
What is the binary equivalent of (24C)16?Each hexadecimal digit is converted to 4-bit patterns:
2 → 0010, 4 → 0100, and C → 1100
The result is (001001001100)2
![Page 125: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/125.jpg)
Octal to Hexadecimal
Hexadecimal
Decimal Octal
Binary
![Page 126: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/126.jpg)
Octal-hexadecimal conversion
![Page 127: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/127.jpg)
Octal−Hexadecimal Conversion
Convert to Binary as an intermediate step
( 0 0 1 0 1 1 0 . 0 1 0 0 )2
( 1 6 . 4 )16
Assume Zeros
Works both ways (Octal to Hex & Hex to Octal)
( 2 6 . 2 )8
Assume Zeros
Example
![Page 128: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/128.jpg)
10768 = ?16
1 0 7 6
001 000 111 110
2 3 E
10768 = 23E16
Example
![Page 129: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/129.jpg)
Decimal, Binary, Octal and Hexadecimal
Decimal Binary Octal Hex00 0000 00 0
01 0001 01 1
02 0010 02 2
03 0011 03 3
04 0100 04 4
05 0101 05 5
06 0110 06 6
07 0111 07 7
08 1000 10 8
09 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
![Page 130: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/130.jpg)
Example
Find the minimum number of binary digits required to store decimal integers with a maximum of six digits.
k = 6, b1 = 10, and b2 = 2. Thenx = [x = [k × (logbk × (logb11 / logb / logb22) ] = [6 × (1 / 0.30103)]= 20.) ] = [6 × (1 / 0.30103)]= 20.
The largest six-digit decimal number is 999,999 and the largest 20-bit binary number is 1,048,575. Note that the largest number that can be represented by a 19-bit number is 524287, which is smaller than 999,999. We definitely need twenty bits.
![Page 131: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/131.jpg)
Hexadecimal to Octal
Hexadecimal
Decimal Octal
Binary
![Page 132: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/132.jpg)
Hexadecimal- Octal Conversion
Convert to Binary as an intermediate step
( 0 0 0 1 0 1 1 0 . 01 0 0 )2
( 1 6 . 4 )16
Assume Zeros
Works both ways (Octal to Hex & Hex to Octal)
( 2 6 . 2 )8
Assume Zeros
Example
![Page 133: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/133.jpg)
1F0C16 = ?8
1 F 0 C
0001 1111 0000 1100
1 7 4 1 4
1F0C16 = 174148
Example
![Page 134: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/134.jpg)
Exercise – Convert ...Decimal Binary Octal Hexadecimal
33
1110101
703
1AF
Decimal Binary Octal Hexadecimal
33 100001 41 21
117 1110101 165 75
451 111000011 703 1C3
431 110101111 657 1AF
![Page 135: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/135.jpg)
Common Powers (1 of 2)
Base 10
Power Preface Symbol
10-12 pico p
10-9 nano n
10-6 micro
10-3 milli m
103 kilo k
106 mega M
109 giga G
1012 tera T
Value
.000000000001
.000000001
.000001
.001
1000
1000000
1000000000
1000000000000
![Page 136: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/136.jpg)
Common Powers (2 of 2)
Base 2
Power Preface Symbol
210 kilo k
220 mega M
230 Giga G
Value
1024
1048576
1073741824
• What is the value of “k”, “M”, and “G”?• In computing, particularly w.r.t. memory, the base-2 interpretation generally applies
![Page 137: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/137.jpg)
Common Powers (2 of 2)
![Page 138: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/138.jpg)
![Page 139: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/139.jpg)
Bits, Bytes, and Words A bit is a single binary digit (a 1 or 0). A byte is 8 bits A word is 32 bits or 4 bytes Long word = 8 bytes = 64 bits Quad word = 16 bytes = 128 bits Programming languages use these standard
number of bits when organizing data storage and access.
What do you call 4 bits?(hint: it is a small byte)
![Page 140: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/140.jpg)
AddingSubtractionMultiplyingDivision
Binary Calculation
![Page 141: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/141.jpg)
Decimal Addition
5 5
55+
011
= Ten ≥ Base Subtract a Base
11 Carry
![Page 142: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/142.jpg)
Binary Addition
Column Addition
1 0 1111
1111 0+
0000 1 11
≥ (2)10
111111
= 61
= 23
= 84
Carry
![Page 143: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/143.jpg)
Binary Addition
![Page 144: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/144.jpg)
Octal Addition
c. 7338 + 748 = ?
Example
a. 1238 + 3218 = ?
1238
+3218
4448
b. 4578 + 2458 = ?
4578
+ 2458
7248
![Page 145: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/145.jpg)
Hexadecimal Addition
c. DF16 + AB16 = ?
d. ADC16 + DEF16 = ?
Example
a. 3316 + 4716 = ?
3316
+ 4716
7A16
b. 20D316 + 12BC16 = ?
20D316
+ 12BC16
338F16
Note:- 2410 =1A16
![Page 146: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/146.jpg)
Question: What is the result of adding 1 to the largest digit of some number system?
• (9)10 + 1 = (10)10
• (7)8 + 1 = (10)8
• (1)2 + 1 = (10)2
• (F)16 + 1 = (10)16
Conclusion: Adding 1 to the largest digit in any number system always has a result of (10) in that number system.
Addition
![Page 147: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/147.jpg)
Binary SubtractionBorrow a “Base” when needed
0 0 1110
1111 0−
0101 1 10
Borrow 2 from next line (2= 10)2
2
22 2
1
000
1
= 77
= 23
= 54
![Page 148: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/148.jpg)
A B A-B Borrow
0 0 0 0
0 1 1 1
1 0 1 0
1 1 0 0
Perform the binary subtraction of the following numbers: 10101 and 01110
Binary Subtraction
![Page 149: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/149.jpg)
Octal Subtraction
a. 5248 - 1678 = ?
5 2 4 8 1 (8+4)
4 (1+8) (12)
(4) (9) (12)
- 1 6 7 8 3 3 5 8
5248 - 1678 = 3358
![Page 150: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/150.jpg)
Octal Subtractiona. 5248 - 1678 = ?
5 2 48 1 (8+4)
4 (1+8) (12) (4) (9) (12) - 1 6 78
3 3 58
5248 - 1678 = 3358
b. 1678 - 248 = ?
1678
- 248
1438
c. 15238 - 3648 = ?
![Page 151: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/151.jpg)
Hexadecimal Subtraction
a . 4416 - 1716 =?
4 416
3 (16 + 4)16
(3) (20)16
- 1 7 16
2 (13) 16
2 D 16
4416 - 1716 = 2D16
![Page 152: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/152.jpg)
Hexadecimal Subtraction
a. 4416 - 1716 =?
4 416 3 (16 + 4)
(3) (20) - 1 716 2 (13)
2 D16
4416 - 1716 = 2D16
b. 20D316 - 12BC16 = ?
20D316
- 12BC16
0E1716
c. DF16 - AB16 = ?
![Page 153: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/153.jpg)
Binary MultiplicationBit by bit
01 1 1 1
01 1 0
00 0 0 0
01 1 1 1
01 1 1 1
0 0 000
0110111 0
x
Example
![Page 154: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/154.jpg)
Example : - Perform the binary multiplication of the decimal numbers 12 and 10.
The equivalent binary representation of the decimal number 12 is 1100.The equivalent binary representation of the decimal number 10 is 1010
Binary Multiplication
![Page 155: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/155.jpg)
Octal Multiplication258 * 168 = ?
258 * 168 =4468
Method 1
Example
![Page 156: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/156.jpg)
Octal MultiplicationMethod 2
![Page 157: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/157.jpg)
Hexadecimal MultiplicationExampl
eEF * D = ?
EF * D = C23
![Page 158: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/158.jpg)
2F * 1A =?
Hexadecimal Multiplication
![Page 159: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/159.jpg)
Hexadecimal mortification table
![Page 160: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/160.jpg)
Binary Division Binary division is also performed in the same way as we
perform decimal division. Like decimal division, we also need to follow the binary subtraction rules while performing the binary division. The dividend involved in binary division should be greater than the divisor. The following are the two important points, which need to be remembered while performing the binary division.
• If the remainder obtained by the division process is greater than or equal to the divisor, put 1 in the quotient and perform the binary subtraction.
• If the remainder obtained by the division process is less than the divisor, put 0 in the quotient and append the next most significant digit from the dividend to the remainder.
![Page 161: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/161.jpg)
Binary DivisionThe equivalent binary representation of the decimal number 18 is 10010.The equivalent binary representation of the decimal number 8 is 1000.
Example
![Page 162: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/162.jpg)
Find the quotient and remainder when 1111101 is divided by 1101 in modulo 2 arithmetic.
We find the quotient is 1011, and the remainder is 0010.
This procedure is very useful to us in calculating CRC syndromes
Binary DivisionExample
![Page 163: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/163.jpg)
Example
Binary Division
![Page 164: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/164.jpg)
Example
Binary Division
![Page 165: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/165.jpg)
Example
Binary Division
![Page 166: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/166.jpg)
Example
Binary Division
![Page 167: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/167.jpg)
Example
Binary Division
![Page 168: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/168.jpg)
Example
Octal Division
738 ÷ 48 = ?
738 ÷ 48 = 168 remain 3
![Page 169: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/169.jpg)
Example
Octal Division
175348 ÷ 648 = ?648 × 2 = 1508
648 × 3 = 2348
![Page 170: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/170.jpg)
Example
Hexadecimal Division
AB16 ÷ 316 = ?
AB16 ÷ 316 = 3916
AB16 ÷ C16 = ?
AB16 ÷ C16 = E.2516
![Page 171: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/171.jpg)
Example
Hexadecimal DivisionDEF16 ÷ AB16 = ?
Note :- Short method
AB16 =10*16 + 11160+11171
DE16 = 13*16 + 14 208 + 14 222
51*16+F=816 + 15 = 831171*4 = 5C4171*E = 142E171*2 = 2E2
![Page 172: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/172.jpg)
Summary of the Division
![Page 173: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/173.jpg)
![Page 174: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/174.jpg)
Bitwise logic
operations
![Page 175: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/175.jpg)
What is an Operator? Operator is an operation performed over data at runtime
Takes one or more arguments (operands) Produces a new value
Operators have precedence Precedence defines which will be evaluated first
Expressions are sequences of operators and operands that are evaluated to a single value
Operators can be classified according to the type of their operands and of their output
Arithmetic Relational Logical Bitwise
the number of their operands Unary (one operand) Binary (two operands)
![Page 176: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/176.jpg)
Categories of Operators in C#
Category Operators
Arithmetic + - * / % ++ --
Relational < <= > >= == !=
Logical && || ^ !
Binary & | ^ ~ << >>
Comparison == != < > <= >=
Assignment = += -= *= /= %= &= |= ^= <<= >>=
String concatenation +
Type conversion is as typeof
Other . [] () ?: new
![Page 177: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/177.jpg)
Binary expression
Unary Expression
![Page 178: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/178.jpg)
Relational operators These perform comparisons and the result is what is
called a boolean: a value TRUE or FALSE FALSE is represented by 0; anything else is TRUE The relational operators are:
< (less than) <= (less than or equal to) > (greater than) >= (greater than or equal to) == (equal to) != (not equal to)
![Page 179: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/179.jpg)
Logical Operators (also called Boolean operators) These have Boolean operands and the result is also a Boolean. The basic Boolean operators are:
Operator ! turns true to false and false to true Behavior of the operators &&, || and ^ (1 == true, 0 == false)
Example :-
bool a = true;
bool b = false;
(a && b) False
(a || b) True
(a ^ b) True
(!b) True
(b || true) True
(b && true) False
(a || true) True
(a && true) True
(!a) False
((5>7) ^ (a==b))
False
&& (logical AND) || (logical OR) ! (logical NOT) -- unary
![Page 180: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/180.jpg)
Logical Operators (also called Boolean operators)
![Page 181: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/181.jpg)
Logical Operators (also called Boolean operators)
Operation ^ ^ ^ ^
Operand1 0 0 1 1
Operand2 0 1 0 1
Result 0 1 1 0
Operation || || || ||
Operand1 0 0 1 1
Operand2 0 1 0 1
Result 0 1 1 1
Operation && && && &&
Operand1 0 0 1 1
Operand2 0 1 0 1
Result 0 0 0 1
![Page 182: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/182.jpg)
BITWISE OPERATORSBitwise operators operate on individual bits of integer (int and long) values.
If an operand is shorter than an int, it is promoted to int before doing the operations.
Negative integers are store in two's complement form. For example, -4 is 1111 1111 1111 1111 1111 1111 1111 1100.
Bitwise operator ~ turns all 0 to 1 and all 1 to 0 Like ! for boolean expressions but bit by bit
The operators |, & and ^ behave like ||, && and ^ for Boolean expressions but bit by bit
The << and >> move the bits (left or right)
Bitwise operators are used on integer numbers (byte, sbyte, int, uint, long, ulong)
Bitwise operators are applied bit by bit
![Page 183: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/183.jpg)
Bitwise OperatorOperator Value
~ Bitwise unary NOT
& Bitwise AND
| Bitwise OR
^ Bitwise XOR
>> Shift Right
>>> Shift Right zero fill
<< Shift left
& = Bitwise AND Assignment
|= Bitwise OR Assignment
^= Bitwise XOR Assignment
>>= Shift Right Assignment
>>>= Shift Right zero fill Assignment
<<= Shift Left Assignment
![Page 184: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/184.jpg)
A B AB
0 0 0
0 1 0
1 0 0
1 1 1
Bitwise Operator
{ A AND B } as A AND B=A ×
BA & B=A ×
B
A A
0 1
1 0
{ NOT A } as
NOT A = A
![Page 185: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/185.jpg)
A B A+B
0 0 0
0 1 1
1 0 1
1 1 1
A B C A+B+C
0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 1
1 0 0 1
1 0 1 1
1 1 0 1
1 1 1 1
Bitwise Operator { A OR B } as follows
A OR B=A+B A | B=A+B
{ A OR B OR C} as follows
A OR B OR C =A+B+CA | B | C= A+B+C
![Page 186: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/186.jpg)
Bitwise Operator
A B AB
0 0 0
0 1 1
1 0 1
1 1 0
{ A XOR B } as A XOR B = (A)B +
A(B)A ^ B = (A)B +
A(B)
Summary
![Page 187: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/187.jpg)
Operation | | | | & & & & ^ ^ ^ ^
Operand1 0 0 1 1 0 0 1 1 0 0 1 1
Operand2 0 1 0 1 0 1 0 1 0 1 0 1
Result 0 1 1 1 0 0 0 1 0 1 1 0
BITWISE OPERATORS
Examples:
a = 3; is 00000011 b = 5; is 00000101
( a | b); // 00000111( a & b); // 00000001( a ^ b); // 00000110(~a & b); // 00000100( a<<1 ); // 00000110( a>>1 ); // 00000001
![Page 188: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/188.jpg)
Bitwise Operator
![Page 189: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/189.jpg)
Bitwise Operator
![Page 190: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/190.jpg)
Bitwise Operator
![Page 191: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/191.jpg)
Bitwise Operator
![Page 192: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/192.jpg)
<-------Bitwise Logical Operators------->
Example :- The binary value of a = 0010 and b = 01111.The Bitwise OR : a | b = 72.The Bitwise AND : a & b = 23.The Bitwise XOR(exclusive OR) : a ^ b = 54.The Bitwise unary NOT : ~a & a = 05.~a&b|a&~b = 5
<-------Bitewise Shift Operators------->
Example :- The original binary value of a = 0010 and Decimal value of a = 21.The Left shift : a = 82. The Right shift : b = b >> 2 = 13.The original decimal value of u = -14. The Unsigned Right shift : u = u >>> 30 means u = 11111111 11111111 11111111 11111111 >>> 30 hence u = 0011 and Decimal value of u = 3
<-------Bitewise Assignment Operators------->
Example :- The original binary value of p = 0101 and Decimal value of p = 5
1.The Bitewise Shift Right Assignment Operators : p >>= 2 means p = p >> hence p =0101 >> 2 so p = 0001 and Decimal value of p = 1
![Page 193: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/193.jpg)
Bitwise OperatorBitwise operators are used in1.Communication stacks where the individual bits in the header attached to the data signify important information
2.Embedded software for controlling different functions in the chip and indicating the status of hardware by manipulating the individual bits of hardware registers of embedded microcontrollers
3.Low-level programming for applications such as device drivers, cryptographic software, video decoding software, memory allocators, compression software and graphics
4.Maintaining large sets of integers efficiently in search and optimization problems
5.Bitwise operations performed on bit flags, which can enable an instance of enumeration type to store any combination of values defined in an enumerator list
![Page 194: Number system part 1](https://reader033.fdocuments.us/reader033/viewer/2022061300/54c90ab84a7959da0f8b4588/html5/thumbnails/194.jpg)
Low level languages are:
1 - Machine Language2 - Assembly Language3 - C (C is not the 100% Low-level language)
High level languages are:
1 - Visual Basic2 - Pascal3 - Java4 - C++and many more.