Binary Complement

  • Thread starter Thread starter RK
  • Start date Start date
R

RK

How can I complement binary numbers so that 0 becomes 1 and 1 becomes
0. Also, is there a way to reverse the order of binary digits (i.e.
write backward)?
 
One way:

Assuming your binary numbers are less than or equal to 10 binary digits,
and you have the Analysis Toolpak Add-in installed (Tools/Add-ins...):

=RIGHT(DEC2BIN(-BIN2DEC(A1)-1),LEN(A1))
 
RK wrote...
How can I complement binary numbers so that 0 becomes 1 and 1 becomes
0. Also, is there a way to reverse the order of binary digits (i.e.
write backward)?

First question:

=TEXT(SUMPRODUCT(1-MID(x,ROW(INDIRECT("1:"&LEN(x))),1),
10^(LEN(x)-ROW(INDIRECT("1:"&LEN(x))))),REPT("0",LEN(x)))

Second question:

=TEXT(SUMPRODUCT(--MID(x,ROW(INDIRECT("1:"&LEN(x))),1),
10^(ROW(INDIRECT("1:"&LEN(x)))-1)),REPT("0",LEN(x)))

This only works for 15 or fewer binary digits. You'd have to chop up
longer binary numbers into 8-byte portions, apply these formulas to the
pieces, then concatenate their results to give the desired results.
 
Back
Top