+ 1

How to find 2's complemet of a binary number in python ?

we have to check number from last and after 1st one occur then after that convert all one to zero and all zero to one .

19th Aug 2017, 1:28 PM
HIMANSHU SHARMA
HIMANSHU SHARMA - avatar
3 Antworten
+ 5
I've just cleared your way dear. Now use your imagination and implement your solution. Good luck.
21st Aug 2017, 4:35 AM
Babak
Babak - avatar
+ 2
suppose we'd like to convert two hex number to its equivalent binary digits. 1. A2 2. 6F Each of these numbers can fit into 8 bit of memory. First I convert both Hex number to binary. A2 = 1010 0010 6F = 0110 1111 Then I look The MSB(Most significant bit) where is in left most position. The rule is, if MSB = 0, then it can't be a signed binary number(2's complement). But if MSB = 1, Then it's going to be a signed binary number. First one Has a MSB of 1 So, we can makes it 2's complement. As you know already, the first step is flipping every single bit. 1010 0010 --> 0101 1101 Now we just add 1 to the LSB(Least significant bit) where is in the right most position. 0101 1101 0000 0001 + ------------------- 0101 1110
20th Aug 2017, 8:00 PM
Babak
Babak - avatar
0
I asked for program .in python
21st Aug 2017, 1:47 AM
HIMANSHU SHARMA
HIMANSHU SHARMA - avatar