Given A Binary Number As A String
Given A Binary Number As A String
1’s complement of a binary number is another binary number obtained by toggling all
bits in it, i.e., transforming the 0 bit to 1 and the 1 bit to 0.In the 1’s
complement format , the positive numbers remain unchanged . The negative numbers
are obtained by taking the 1’s complement of positive counterparts.
Examples:
Examples:
Step 2: Once you have found 1, let the 1 as it is, and now
Illustration
Suppose we need to find 2s Complement of 100100
Step 1: Traverse and let the bit stay the same until you find 1. Here x is not
known yet. Answer = xxxx00 –
Step 3: Flip all the bits left into the 1. Answer = 011100.