Please enable JavaScript.
Coggle requires JavaScript to display documents.
Chapter 2.1 ARITHMETIC AND LOGIC (Data Representation In Computer…
Chapter 2.1 ARITHMETIC AND LOGIC
(Data Representation
In Computer Memory)
Binary
BINARY CODE DECIMAL (BCD)
-Some codes are unused, like 1010BCD, 1011BCD, … 1111BCD. These codes are considered as errors.
-Easy to convert, but arithmetic operations are more complicated
-Suitable for interfaces such as keypad inputs.
Example
-(234)10 = (0010 0011 0100) BCD
-(7093)10 = (0111 0000 1001 0011)BCD
-(1000 0110)BCD = (86)10
-(1001 0100 0111 0010)BCD = (9472)10
If each digit of a decimal number is represented by its binary equivalent, the result is a code called binary-coded-decimal.
Decimal digit can be as large as 9, four bits are required to code each digit (the binary code for 9 is 1001)
Decimal
Universally used to represent
quantities outside a digital system.
Its means, there will be situations decimal values must be converted to binary values before entered to digital system.
Example : Calculator / Computer
Decimal system is composed of 10 numerals
or symbols.
These 10 sysmbols are 0, 1, 2, 3, 4, 5, 6,
7, 8, 9.
Using these symbols as digits of a
number, it can express any quantity
Example : 234^10
Decimal-to-Octal Conversion
Decimal integer can be converted to octal by using the same repeated-division method with a division factor of 8.
DECIMAL CODES
-Decimal numbers are favoured by humans. Binary numbers are natural to computers. Hence, conversion is required.
-If little calculation is required, we can use some coding schemes to store decimal numbers, for data transmission purposes.
-Examples: BCD (or 8421), Excess-3, 84-2-1, 2421, etc.
-Each decimal digit is represented as a 4-bit code.
-The number of digits in a code is also called the length of
the code.
Octal
The octal number system has a base of eight, meaning that it has eight possible digits: eight possible digits:
0,1,2,3,4,5,6 and 7
The digit positions in an octal number have weights as follows :
8^3 8^2 8^1 8^0 . 8^-1 8^-2
Octal –to- Binary conversion
Converting from octal to binary is as easy as converting from binary to octal. Simply look up each octal digit to obtain the equivalent group of three binary digits.
Hexadecimal
The hexadecimal number system uses base
16.
It has 16 possible digit symbols
It uses the digits 0 through 9 plus the letters
A, B, C, D, E and F as the 16 digit symbols.
Example: 7A^16
Hexadecimal-To-Decimal Conversion
A hexadecimal number can be converted to its decimal equivalent by using the fact that each hex digit position has a weight that is a power of 16
Decimal-To-Hexadecimal Conversion
Decimal to hex conversion can be done using
repeated division by 16.
Hexadecimal-to-Binary Conversion
Like the octal number system, the hexadecimal number system is used primarily as a “shorthand” method for representing binary numbers
It is a relatively simple matter to convert a
hex number to binary .
Each hex digit is converted to its four-bit
binary equivalent.
Binary-to-Hexadecimal Conversion
The binary number is grouped into groups of four bits, and each group is converted to its equivalent hex digit.
Zero are added, as needed to complete a
four-bit group.
NEGATIVE NUMBERS
REPRESENTATION
Unsigned numbers: only non-negative values.
In un-signed number system all the bits directly correspond to the equivalent decimal number.
Example:
100011 binary = 35 decimal
000011 binary = 3 decimal
Signed numbers: include all values (positive and
negative)
In signed number system the most significant bit (MSB) bit signifies sign of all lower significant bit (LSB) bits for the number.
Example
100011 binary = -3 decimal
000011 binary = +3 decimal
There are 3 common representations for signed binary numbers:
Sign-and-Magnitude
1s Complement
2s Complement
1s Complement
-One’s complements is used in binary
number.
-The one’s complement of a binary number is obtained by changing each 0 to 1 and 1 to a 0.
-Only change negative number
-In other words, change each bit in the number to its complement.
Example
-10011001 = 01100110
-Thus, we say that the 1’s complement of 10011001 is 01100110.
1s COMPLEMENT ADDITION/SUBTRACTION
Algorithm for addition, A + B:
Perform binary addition on the two numbers.
If there is a carry out of the MSB, add 1 to the result.
Check for overflow. Overflow occurs if result is opposite sign of
A and B.
Algorithm for subtraction, A – B:
A – B = A + (-B)
Take 1s-complement of B.
Add the 1s-complement of B to A.
Subtraction in 1’s complement
-Only binary number which have –ve sign need to change to 1’s complement. If the number is decimal number, change the number to binary number
-The –ve number that already change to 1’s complement, means that the number already change to +ve. So that, the subtraction process have change to addition process.
Overflow bit in addition process need to carry to LSB and add with the number.
2s Complement
-The 2’s complement of a binary number is formed by taking the 1’s complement of the number and adding 1 to the least-significant-bit (LSB) position.
Subtraction in 2’s complement
-Change the number are given to binary number
-For each –ve binary number, we must change to 1’s complement (change 0 to 1 and 1 to 0).
Then, add the number with 1
Sign And Magnitude
The sign is represented by a ‘sign bit’
Example
0 for +
1 for -
Largest value: 01111111 = +127^10
Smallest value: 11111111 = -127^10
Zeros: 00000000 = +0^10 / 10000000 = -0^10
Range: -127^10 to +127^10
ASCII Code
-The most widely used alphanumeric code is the American Standard Code for Information Interchange (ASCII).
-The ASCII code is a seven-bit code and so it has 2^7 = 128 possible code groups.