Home » C Program To Convert Binary Number To 2’s Complement

C Program To Convert Binary Number To 2’s Complement

A 2’s complement is used for binary operations in a computer system. In this example program, you are going to receive a binary string and convert the string into 2’s complement in two steps.

Learn the basics of C programming before you begin with the example. Skip this step if you already familiar with these concepts.

Problem Definition

The program ask for a input binary string. To convert this binary string in to 2’s complement, you need two steps.

  1. Convert the input binary string to 1’s complement.
  2. Add 1 to the 1’s complement obtained.

For example, suppose a the input string is 1100.

Step 1: The 1’s complement can be obtained by converting 1’s in to 0 and 0s into 1s.

1100 becomes 0011

Step 2: Add 1 to the 1’s complement to get 2’s complement of the number.

This step requires you to understand the binary math.

(adsbygoogle = window.adsbygoogle || []).push({}); </script

Please support us by disabling your adblocker or whitelist this site from your adblocker. Thanks!

turn of adblocker imag

(adsbygoogle = window.adsbygoogle || []).push({});