I have this simple problem which for some reason I have trouble with I'll be glad to get help.
I have these two numbers in base 10 :
5250, 321.
I change the basis from 10 to 9 then I get :
5250 --> 7173
321 ---> 386
I use the method of r complement with base 9:
First of all I'll find the the complement of 0386 in base 9 which is 6561-386=6175.
Therefore :
7173+6175=14358 (in base 9)
since its a complement to 9, we receive 4358 in base 9
Which is incorrect.
Any ideas why my method is incorrect?
Any help will be appreciated.
you are mixing bases. 6561 is base 10 for 10000 in base 9.
You need to calculate 100000 - 386 in base 9 to get the complement. This results in 88503. So 88503 is the 10's complement of 386 in base 9. Note the extra digit, otherwise 7173 will be a negative number in this representation.
Now you can calculate 7173 + 88503 = 106676. So the result is 6676 which is 4929 in decimal, which is the expected result.
Related
For the purposes of teaching, I wish to understand the following in the context of the method (four steps, see below): I am trying to convert +7 to twos complement in 8 bits. The answer, as per shown on https://www.allmath.com/twos-complement.php is as below:
Decimal 7
Binary 0000 0111
Complement 1111 1001
This shows a negative number as it starts with 1.
Shouldn't the answer be 0111.
I want to be able to derive the answer using these four steps.
STEP 1: Convert magnitude (7) to binary. 0111
STEP 2: Pad 0's to desired bit size. 0000 0111
STEP 3: Invert bits to achieve 1's-complement. 1 1 1 1 1 0 0 0
STEP 4: Add 1 to achieve 2's-complement.
ADD 1
------------------>
1 1 1 1 1 0 0 1
Where am I going wrong in understanding this. When working with twos complement numbers we were taught that if it started with a 1 it was negative. So what is a method for converting positive decimal numbers into twos complement, or do we assume that for any positive decimal number the twos complement is just itself:
e.g 7 = 0111 or 0000 0111 if in 8 bits?
This would also suggest then that the 4 step method above CANNOT be used for POSITIVE numbers?
Discussion
(note that discussion here uses TCR for "Two's Complement Representation")
Unfortunately, the material you provided here (allmath.com) probably misunderstood what is "Two's Complement". There are many books have provide the canonical definitions for it, for the sake of convenience, it suffices to quote from Wikipedia:
The very first sentence:
Two's complement is a mathematical operation on binary numbers
, along with the definition for its mathematical operation:
w = -a_{n-1}2^{n-1} + a_{n-2}2^{n-2} + ... + a_{0}2^{0}
Take a binary number 11111001 as an example. Without TCR, we can interprate it as 2^7 + 2^6 + 2^5 + 2^4 + 2^3 + 1 = 249. With TCR (i.e. applying the mathematical operation), we view it as -2^7 + 2^6 + 2^5 + 2^4 + 2^3 + 1 = -7.
Similiary, for another binary number, say 00000111. Without TCR, we view it as 2^2 + 2^1 + 1 = 7. And with TCR, we view it as 2^2 + 2^1 + 1 = 7, which is identical to the former one.
Back to your scenario
Your 4-step operations are essentially: obtaining the TCR for the negation of a given number.
Again, taking 11111001 as an example, after your 4-step operations, it turns into 00000111, which is 7, i.e. the negation of -7 (11111001). Similiary, after your 4-step operations, 00000111 turns into 11111001, which is -7, i.e. the negation of 7 (00000111). Thus, the result of your 4-step operations is call Two's Complement Negation, instead of Two's Complement.
Why is easy to be confusing?
One reason might be: Nearly all computers adopt the TCR notion. Assuming a 8-bit computer, when we want to see how would our computer display the decimal number 7, our computer would directly print out 7, which is very intuitive for most people. However, for decimal number 249, it usually does not "obey your commands", instead, it prints out the another value: -7.
Conversely, if you want your computer to display -7, accoding to Cornell University's Lecture Notes, the things you need to do are:
Start from the absolute value of -7, which is 7;
Take 7's binary representation (i.e. 00000111) as input.
Invert the bits.
Add one. (note that 1~4 are exactly equivalent to your 4-step operations)
Give the result to your computer.
Then our computer would get a binary representation 11111001 (it's 249 in decimal), and it would display it with -7 on your screen.
In this scenario, you could fairly say that, in an 8-bit computer using TCR, -7 is the alternative representation of the two's complement number 249. Although this saying is not much canonical, it helps someone who just learned the notion of TCR for the first time.
In terms of the notion of TCR, please refer to Wikipedia, University Lecture Notes or CS books for more precise details, instead of many so-called "online crash courses".
Hello I would like to know of a quick and easy way to perform a number conversion of this binary value:
1000100000001011
to octal.
In hex I can convert fairly quickly by hand to 0xAA0B. To come up with the decimal value of this binary takes a bit more work but eventually you can arrive at 32,768 + 2,048 + 11 = 34,827.
I know the octal pattern works like 8 = 10, 9 = 11 .... 16 = 20, 17 = 21 ... 24 = 30, etc. However I am having trouble converting to octal without a large amount of effort.
Could anybody clear this up for me and perhaps provide a short-hand method that can help convert binary to octal. Programming examples are nice but I'm really looking for an explanation. Thanks
The quickest method is to break the binary number into 3-bit chunks from the right end, pad with 0's from the left as needed, then convert each chunk to an octal digit.
For example,
1000100000001011 -> 001 000 100 000 001 011 [2 0's added to the left]
-> 1 0 4 0 1 3
-> 104013
Either there is some confusion with what is written below or my textbook is wrong.
I was looking at examples in my textbook for addition of 8 bit signed binary digits using 2's complement and came across these examples.
We are required to find if any overflow occurs
Example 1]
Adding +75 and -58
+75 = 01001011 ... (a)
+58 = 00111010
-58 = 11000110 ... (b) [took 2's complement of +58]
now adding (a) and (b) we get
01001011
+ 11000110
1]00010001
It was written in textbook that overflow occurs with an arrow pointing to that extra 1 separated with a square bracket.
This example is ok and from here I understood that if there is and extra 1 then we have a overflow.
(Question 1: Am i correct with what i understood ?)
Example 2: This example confused me
Add 53 and (-13)
53 = 00110101
-(13) = 11110011
now adding both we get
00110101 + 11110011 = 1]00101000
And then they wrote: Carry in and carry out for signed bit is 1. So no overflow. Discarding the carry bit and rest is the positive required result
(The main Question: Even though there was this overflow digit(extra 1) why did they say its not overflow. And what are these carry in and carry out for signed bit written in above sentence.)
I did a lot of Google search but couldn't find a good reasonable solution to this line they talked about, or may be it was in front of my eyes but i didn't understand. Somebody please clarify. Most examples I saw(on stack-overflow and other sites) were for 4 bits that confused a bit more. Somebody please help me clarify, Thanks.
Overflow occurs only when correct answer cannot be interpreted using given number of bits.An extra bit is required to interpret the answer right.Consider the following example of byte numbers addition:
+70 in binary 01000110
+80 in binary 01010000
On addition :10010110
1 in the MSB(most significant bit) indicates that answer is negative which is wrong.However if we include an extra 9th bit as a sign bit(=0) we have the answer as 010010110 = 150.The value of this extra sign bit is equal to the carry as a result of addition of bits in MSB(which in this case = 0).
Reference : Computer System Architecture by M.Morris Mano.
I will try to resolve your doubt with the help of examples, where we will ADD two numbers using signed 2's complement method.
But before that let me tell you the condition when Overflow occur.
Basically, overflow occur when carry into the sign bit is not equal to the carry out of the sign bit.
Example Number 1:
Decimal Carry out Sign bit 2’s Complement
-65 - 1 011 1111
-15 - 1 111 0001
---------------------------------------------
-80 1 1 011 0000
1's complement of 0110000 = 1001111
Adding Overflow digit 1 to 1001111 we will get our answer as 1010000.
With signed bit we will get - 1 1010000 which is equal to -80
Carry into the Sign bit = 1
Carry out of the Sign bit = 1
Therefore, No OVERFLOW
Example Number 2:
Decimal Carry out Sign bit 2’s Complement
-65 - 1 011 1111
-75 - 1 011 0101
--------------------------------------------
-140 1 0 111 0100
Carry into the Sign bit = 0
Carry out of the Sign bit = 1
Therefore, OVERFLOW
I hope, that this must have cleared your doubts about Overflow and signed 2's complement Binary Addition technique.
simplest rule while calculating 8 bit number.
Carry-Bit | Sign-Bit
-----------------------------------------------------
0 | 0 --> No Underflow or Overflow
1 | 1 --> No Underflow or Overflow
0 | 1 --> OVerflow
1 | 0 --> Underflow
Add the following using 8 bit signed 2's complement representation:
25 and -40
75 and 80
Suppose system is evolved by extraterrestrial creatures having only 3 figures and they use the figures 0,1,2 with (2>1>0) ,How to represent the binary equivalent of 222 using this?
I calculated it to be 22020 but the book answers it 11010 .how this.Shouldn't i use the same method to binary conversion as from decimal to binary except using '3' here ???
I think you meant base 3 (not binary) equivalent of decimal 222
22020 in base 3 is 222 in decimal.
220202(your answer) in base 3 is 668 in decimal.
11010 (according to book) in base 3 is 111 in decimal.
222 in binary is 11011110
May be i will be able to tell where you went wrong if you tell the method you used to calculate base 3 equivalent of 222
Edit:
Sorry I could not understand the problem until you provide the link. It says what is binary equivalent of 222 (remember 222 is in base 3)
222 in base 3 = 26 in decimal (base 10)
26 in decimal = 11010 in binary
Mark it as accepted if it solved your problem.
Assuming the start is decimal 222.
Well, without knowing the system used in the book I would decompose it by hand in the following way:
3^4 = 81,
3^3 = 27,
3^2 = 9,
3^1 = 3,
So 81 fits twize into 222 , so the 4th "bit" has the value 2.
Remaining are 60. 27 fits twice into 60 so the next bit is 2 again.
Remaining are 6. 9 fits not into 6, so the next bit is 0.
Remaining are 6. 3 fits twice into 6, so the next bit is 2.
remaining are 0. so the last bit 0
This gives as result 22020.
One quick sanity check on how many "bits" are needed for representation of decimal 222 in a number system with 3 Numbers: 1+log(222)/log(3)=5,9 => nearly 6 "bits" are needed, which goes well with the result 22020.
First see how many figures you have, here we have 3 so
we have to convert 222 to binary when we have only 3 figures so
2×3^2+2×3^1+2×3^0 (if the number were being 121 then →
1×3^2+2×3^1+1×3^0)
which gives 26 then divide this with 2 until we don't get 1/2
when reminder is 1 then write 1 if 0 then 0 you will get
so we get 01011 just reverse it we have the answer
11010
enter image description here
i want to do the following subtraction using ones complement
Octal(24)-Hex(4B) and give a binary answer
Octal(24) is 20 decimal
and Hex(4B) is 75 in decimal
20->10100
75->1001011
taking 1s complement of 75
0110100 and adding to 20
10100
+0110100
=1001000
adding the carry with the result
001000
+ 1
=001001 which is wrong
Where am i going wrong ?
I am new here, sorry if any mistakes in the way its typed.
You have a small few mistakes in your version. let me show you a correct solution and then show you your mistake(s)
We have the octal number 24 and the hex number 4B. both are fairly easy to translate to binary.
every octal digit represents 3 binary digits.
2 4
+++ +++
010 100
every hexadecimal digit represents 4 digits.
4 B
++++ ++++
0100 1011
now you build the complement:
~01001011
---------
10110100
the you need to add one. Otherwise you get 2 zeros. (+0 => 00000000, -0 => 11111111). this actually makes it a two's complement, but its needed unless you want weird results when crossing the 0-border
10110100
+00000001
---------
10110101
now your complement is done. Next step is to add both numbers
00010100 #The Octal 24
+10110101 #The complement
---------
11001001
The first digit is a 1 therefore its negative (as we'd expect since we did 20 - 75)
Therefore we need to reverse it.
First we subtract one: 11001000
Then we invert it again: 00110111
Which is decimal 55. Therefore 11001001 is decimal -55.
20 - 75 = -55
Voila, we are done :)
First tiny note: you made a small mistake when converting 0x4B (= Hex 4B) into binary format. one digit is wrong :)
Also, you forgot to add one. Then you did some weird stuff i don't get here:
adding the carry with the result 001000 + 1 =001001 which is wrong
Also, you didn't use fixed size numbers which made it impossible to you to find out if the result was negative. I sticked to 8 Bit here (except during octal -> binary conversion). (Keep in mind that with 8 bit your number range is from -127 to +128.) And in the end - as you couln't see its a negative number - you did not revert the process.
I hope this explanation helped you out :)