Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Computing 2's complement in Excel

Tags:

excel

binary

How can I compute the 2s complement of a binary number in Excel. Which Excel functions do I need?

For example, if I have the binary sequence 11101010, the 2s complement can be obtained as,

  1. Replace all 1's with 0's and 0's with 1's: 00010101
  2. add 1 to the result of step 1: 00010110

An excel implementation of the above is what I need.

like image 539
flowers1234 Avatar asked Oct 16 '25 21:10

flowers1234


1 Answers

Remember that Two's complement was invented as a way to to a subtraction in a computer to represent negative numbers, so this problem can be solved as a simple subtraction, so get the complement and then add one.

=DEC2BIN(255 - BIN2DEC(A1) + 1)

Where A1 is a cell with a binary number as text. If you want to use a bigger number then use the biggest number that can be represented by the number of bits that you want to use, here my example is for 8 bits, so (2^8)-1 = 255

like image 76
Guillermo Adrian Rodrguez Barr Avatar answered Oct 18 '25 14:10

Guillermo Adrian Rodrguez Barr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!