BCD subtraction using 10`s Compliment in Binary or Machine Code
Good day. I will provide a method for subtracting any number positive or negative using a pattern known maybe since the 1960`s. However in the books and online tutorials some of the implications is not done on the binary level. I wanted to see if it was possible to do a integer subtraction using 10s compliment in pure binary on paper. This is what I came up with.
There are certain rules that makes a binary addition, and other rules for making a subtraction. If the methods of addition and subtraction were alike, then they would all be the same function . A different "construct" is therefore needed to produce a Multiplication and yet another "pattern or program" to perform a Division. So these rules must be studied separately. These aritmetic "programs" is actually hardware patterns of electricity over a network of transistors, and in binary this is what the programmers refer to as "machine code". Pressing the + on the calculator actually "loads a program" These units are called ALU Arithmetic Logic Units in the computer arthitecture. I use the book
X86 Assembly Language and C fundamentals by Joseph Cavanagh,
and recommend the book for studies, and begin on page 1. It is always a good idea to sharpen the skills on basic school math. Do you think they used a calculator to design the calculator ? Bring your pencil and paper ! And a steaming hot coffee, if you like .
I will first do it in Decimal 10 or ordinary numbers subtraction explaining the process, then move on to the binary. A computer only allows additions and special measures must be made to perform a subtraction. The number to be subtracted (subtrahend) must be inverted then added +1, this is in the name of Horus ! After that the inverted negative is added to the first value ( minuend ) . BCD is a number that is grouped in 4 bits per integere. Integere is a whole number like 1, 7 and 9, or 82. A fractional number is 1.234 .
STEP 1A
27
-43
= -24 error
When trying to subtract these numbers by hand . or "long math" it proves difficult. For the numbers is not making sense. the 7 - 3 = 4. and 2 - 4 = - 2 if one borrows from the "nothingness" The answer is however wrong if differance is - 24 . So it must be done otherwise. Try to displace the position of 43 and 27.
STEP 1B
4 3 Minuend
- 2 7 Subtrahend
10 borrow from 40 in 43
= 3 +3 Number is now "Thirty Thirteen"
- 2 -7
= 1 6
= +1 6 Differance
The number 16 is correct but the sign is wrong.
However the number we are looking for is 16.
STEP 2
Find the 10s Compliment of Subtrahend.
10s compliment is a method to negate a number, so a Subtraction can be performed as an Addition. The method is to subtract each digit, or the number as a whole by Radix - 1. In our case Radix is 10. Making 10 - 1 = 9. Radix is the counting system. Radix 2 is Binary. Radix 8 is Octal and Radix 16 is Hexadecimal. One counts to the largest number then starts the loop again, a number in Hex 4CF would be pronounced : Four Hundred and Twelvty Fifteen ! for this to function the differance must be added 1 on the Lo-bit or LSB, Least Significant Bit.
9 9 10s compliment
- 4 3 Subtrahend
+ 1 Add 1 for Horus
=+ 5 7 is 10s compliment of -43
STEP 3
BCD arithmetic
We add the 27 to the 10s compliment of -43, that is noe established +57
2 7 Minuend
+ 5 7 10s Compliment of Subtrahend
=+ 8 4 10s Compliment Differance
STEP 4
convert +84 back out of 10s compliment negative to a inverted positive or a negative number.
9 9
- 8 4
+ 1 Add 1 for Horus
= 1 6 since this number is inverted from 10s complimetn that was positive , this number is signed negative. and a -16,
Now over to the binary.
STEP 1A establish long math methods that is false, we skip it.
STEP 1B establish the decimal number one is looking for, namely 16.
STEP 2
Find 10s Compliment of -43
0100 0011 43 BCD
1011 1100 Invert BCD
0001 0001 Add 1 to each integere because it is inverted requires a + 1 operation.
- - - - - - - - - -
1100 1101 -43 complete
1001 1001 +99 Compliment number
- - - - - - - - - -
10101 10110 Differance
0000 0001 Add 1 for Horus ( Radix Compliment requires a +1 to LSB to inverted operation)
- - - - - - - - -
10101 10111 Overflow MSB is converted to a + sign ( operand) then discarded.
+0101 +0111 = +57 BCD
STEP 3
BCD Arithmetic.
It is worth knowing that the BCD is 6 numbers short of a full Hexadecimal 4 bit cycle. Implying that the Bit register that can count to 16 values over a range of 0 to 15 on the binary weights 1111 = 15. In BCD, 6 values are discarded because of human interaction, we count in radix 10 or decimal system. Deca or Deci means 10, This implies that in BCD arithmetic, once the number exceeds 10, BCD is greater > than 1010_2 then add 6_10 ( 0110_2) to that value. Called the "Excess 6" adjustment. Notice also that Each integere is first inverted and added 1 separately. However at the 10s compliment only 1 is added to the LSB.
0010 0111 27 BCD establish Minuend
0101 0111 +57 10s compliment of Subtrahend
1110 >10 value is greater than 10 in BCD.
0110 +6 Excess 6 rule to BCD
10110 Overflow MSB bit is Carried to next integere and added.
1 0110 MSB is carried to next integere.
1001
1000 0100 = +84 This is the differance in 10`s compliment.
STEP 4
Convert Differance in 10s compliment to inverted value of inverted sign.
1000 0100 +84 BCD
0111 1011 invert BCD
0001 0001 add 1 to each integere after invertion.
- - - - - - - - - - -
1000 1100 -84 complete
1001 1001 +99 10s compliment
- - - - - - - - - - -
10001 10101 = Differance
0000 0001 Add 1 for Horus to the LSB, because of inverted operation of 10s comp
- - - - - - - - - - -
10001 10110 = Overflow Hi-bit MSB is converted to opposite sign then discarded.
- 0001 -0110 = -1 - 6 = -16 the number is -16
I also have a drawing that show a slight other arrangement,
and it has the carrys in the addition !
first I didnt think it was possible and converted the 10s compliment into a 8 bit signed integere.
Preume the numbers
STEP 1
0 7
- 3 8
= - 3 1
STEP 2
2^7 2^6 2^5 2^4 2^3 2^2 2^1 2^0 Leibniz positional weight system
SIGN
+ - 64 32 16 8 4 2 1
0 0 1 0 0 1 1 0 38 subtrahend
1 1 0 1 1 0 0 1 Inverted
0 0 0 0 0 0 0 1 Add 1 for Horus
- - - - - - - - - - - - - - - - - - - - -
1 1 0 1 1 0 1 0 -38
0 1 1 0 0 0 1 1 99 10s compliment
- - - - - - - - - - - - - - - - - - - - -
1 0 0 1 1 1 1 0 1 overflow MSB is fed back to add LSB
0 0 0 0 0 0 0 1 MSB becomes LSB add
0 0 1 1 1 1 1 0 = 62 in 10s compliment
+32 +16 +8 +4 +2 = 62 Leibniz positional weight
STEP 3
BCD arithmetic
Convert values from Binary to BCD
0 0 0 0 0 1 1 1 07 Minuend
0 1 1 0 0 0 1 0 62 Subtrahend ( inverted -38)
0 1 1 0 1 0 0 1 = 69 in 10s Compliment
STEP 4
Convert BCD to Binary
Use Double Dabble. Shift left, when BCD is > 4 (5 or more ). then Add 3.
0 1 0 0 0 1 0 1 69 10s comliment of differance.
- - - - - - - - - - - - - - - - - - - - -
1 0 1 1 1 0 1 0 Invert
0 0 0 0 0 0 0 1 Add 1 for Horus
- - - - - - - - - - - - - - - - - - - - -
1 0 1 1 1 0 1 1 = -69 in 10s compliment
0 1 1 0 0 0 1 1 99 10s compliment
- - - - - - - - - - - - - - - - - - - - -
1 0 0 0 1 1 1 1 0 Overflow MSB is fed back to LSB
0 0 0 0 0 0 0 1 MSB to LSB add.
- - - - - - - - - - - - - - - - - - - - -
0 0 0 1 1 1 1 1 = 31 Binary 8 bit output value.
+16 +8 +4 +2 +1 = - 31 since the value is inverted twice.
Cheers.
Kenneth H. Olsen
There are certain rules that makes a binary addition, and other rules for making a subtraction. If the methods of addition and subtraction were alike, then they would all be the same function . A different "construct" is therefore needed to produce a Multiplication and yet another "pattern or program" to perform a Division. So these rules must be studied separately. These aritmetic "programs" is actually hardware patterns of electricity over a network of transistors, and in binary this is what the programmers refer to as "machine code". Pressing the + on the calculator actually "loads a program" These units are called ALU Arithmetic Logic Units in the computer arthitecture. I use the book
X86 Assembly Language and C fundamentals by Joseph Cavanagh,
and recommend the book for studies, and begin on page 1. It is always a good idea to sharpen the skills on basic school math. Do you think they used a calculator to design the calculator ? Bring your pencil and paper ! And a steaming hot coffee, if you like .
BCD subtraction in 10s Compliment in Decimal
I will first do it in Decimal 10 or ordinary numbers subtraction explaining the process, then move on to the binary. A computer only allows additions and special measures must be made to perform a subtraction. The number to be subtracted (subtrahend) must be inverted then added +1, this is in the name of Horus ! After that the inverted negative is added to the first value ( minuend ) . BCD is a number that is grouped in 4 bits per integere. Integere is a whole number like 1, 7 and 9, or 82. A fractional number is 1.234 .
Subtraction
Minuend
- Subtrahend
= Differance
STEP 1A
27
-43
= -24 error
When trying to subtract these numbers by hand . or "long math" it proves difficult. For the numbers is not making sense. the 7 - 3 = 4. and 2 - 4 = - 2 if one borrows from the "nothingness" The answer is however wrong if differance is - 24 . So it must be done otherwise. Try to displace the position of 43 and 27.
STEP 1B
4 3 Minuend
- 2 7 Subtrahend
10 borrow from 40 in 43
= 3 +3 Number is now "Thirty Thirteen"
- 2 -7
= 1 6
= +1 6 Differance
The number 16 is correct but the sign is wrong.
However the number we are looking for is 16.
STEP 2
Find the 10s Compliment of Subtrahend.
10s compliment is a method to negate a number, so a Subtraction can be performed as an Addition. The method is to subtract each digit, or the number as a whole by Radix - 1. In our case Radix is 10. Making 10 - 1 = 9. Radix is the counting system. Radix 2 is Binary. Radix 8 is Octal and Radix 16 is Hexadecimal. One counts to the largest number then starts the loop again, a number in Hex 4CF would be pronounced : Four Hundred and Twelvty Fifteen ! for this to function the differance must be added 1 on the Lo-bit or LSB, Least Significant Bit.
9 9 10s compliment
- 4 3 Subtrahend
+ 1 Add 1 for Horus
=+ 5 7 is 10s compliment of -43
STEP 3
BCD arithmetic
We add the 27 to the 10s compliment of -43, that is noe established +57
2 7 Minuend
+ 5 7 10s Compliment of Subtrahend
=+ 8 4 10s Compliment Differance
STEP 4
convert +84 back out of 10s compliment negative to a inverted positive or a negative number.
9 9
- 8 4
+ 1 Add 1 for Horus
= 1 6 since this number is inverted from 10s complimetn that was positive , this number is signed negative. and a -16,
Now over to the binary.
BCD subtraction using 10`s Compliment in Binary or Machine Code
STEP 1A establish long math methods that is false, we skip it.
STEP 1B establish the decimal number one is looking for, namely 16.
STEP 2
Find 10s Compliment of -43
0100 0011 43 BCD
1011 1100 Invert BCD
0001 0001 Add 1 to each integere because it is inverted requires a + 1 operation.
- - - - - - - - - -
1100 1101 -43 complete
1001 1001 +99 Compliment number
- - - - - - - - - -
10101 10110 Differance
0000 0001 Add 1 for Horus ( Radix Compliment requires a +1 to LSB to inverted operation)
- - - - - - - - -
10101 10111 Overflow MSB is converted to a + sign ( operand) then discarded.
+0101 +0111 = +57 BCD
STEP 3
BCD Arithmetic.
It is worth knowing that the BCD is 6 numbers short of a full Hexadecimal 4 bit cycle. Implying that the Bit register that can count to 16 values over a range of 0 to 15 on the binary weights 1111 = 15. In BCD, 6 values are discarded because of human interaction, we count in radix 10 or decimal system. Deca or Deci means 10, This implies that in BCD arithmetic, once the number exceeds 10, BCD is greater > than 1010_2 then add 6_10 ( 0110_2) to that value. Called the "Excess 6" adjustment. Notice also that Each integere is first inverted and added 1 separately. However at the 10s compliment only 1 is added to the LSB.
0010 0111 27 BCD establish Minuend
0101 0111 +57 10s compliment of Subtrahend
1110 >10 value is greater than 10 in BCD.
0110 +6 Excess 6 rule to BCD
10110 Overflow MSB bit is Carried to next integere and added.
1 0110 MSB is carried to next integere.
1001
1000 0100 = +84 This is the differance in 10`s compliment.
STEP 4
Convert Differance in 10s compliment to inverted value of inverted sign.
1000 0100 +84 BCD
0111 1011 invert BCD
0001 0001 add 1 to each integere after invertion.
- - - - - - - - - - -
1000 1100 -84 complete
1001 1001 +99 10s compliment
- - - - - - - - - - -
10001 10101 = Differance
0000 0001 Add 1 for Horus to the LSB, because of inverted operation of 10s comp
- - - - - - - - - - -
10001 10110 = Overflow Hi-bit MSB is converted to opposite sign then discarded.
- 0001 -0110 = -1 - 6 = -16 the number is -16
I also have a drawing that show a slight other arrangement,
and it has the carrys in the addition !
Another method that is making the 10s compliment in 8bit binary.
first I didnt think it was possible and converted the 10s compliment into a 8 bit signed integere.
Preume the numbers
STEP 1
0 7
- 3 8
= - 3 1
STEP 2
2^7 2^6 2^5 2^4 2^3 2^2 2^1 2^0 Leibniz positional weight system
SIGN
+ - 64 32 16 8 4 2 1
0 0 1 0 0 1 1 0 38 subtrahend
1 1 0 1 1 0 0 1 Inverted
0 0 0 0 0 0 0 1 Add 1 for Horus
- - - - - - - - - - - - - - - - - - - - -
1 1 0 1 1 0 1 0 -38
0 1 1 0 0 0 1 1 99 10s compliment
- - - - - - - - - - - - - - - - - - - - -
1 0 0 1 1 1 1 0 1 overflow MSB is fed back to add LSB
0 0 0 0 0 0 0 1 MSB becomes LSB add
0 0 1 1 1 1 1 0 = 62 in 10s compliment
+32 +16 +8 +4 +2 = 62 Leibniz positional weight
STEP 3
BCD arithmetic
Convert values from Binary to BCD
0 0 0 0 0 1 1 1 07 Minuend
0 1 1 0 0 0 1 0 62 Subtrahend ( inverted -38)
0 1 1 0 1 0 0 1 = 69 in 10s Compliment
STEP 4
Convert BCD to Binary
Use Double Dabble. Shift left, when BCD is > 4 (5 or more ). then Add 3.
0 1 0 0 0 1 0 1 69 10s comliment of differance.
- - - - - - - - - - - - - - - - - - - - -
1 0 1 1 1 0 1 0 Invert
0 0 0 0 0 0 0 1 Add 1 for Horus
- - - - - - - - - - - - - - - - - - - - -
1 0 1 1 1 0 1 1 = -69 in 10s compliment
0 1 1 0 0 0 1 1 99 10s compliment
- - - - - - - - - - - - - - - - - - - - -
1 0 0 0 1 1 1 1 0 Overflow MSB is fed back to LSB
0 0 0 0 0 0 0 1 MSB to LSB add.
- - - - - - - - - - - - - - - - - - - - -
0 0 0 1 1 1 1 1 = 31 Binary 8 bit output value.
+16 +8 +4 +2 +1 = - 31 since the value is inverted twice.
Cheers.
Kenneth H. Olsen
Kommentarer