Binary NOT in excel

jackleg

New Member
Joined
Oct 13, 2002
Messages
6
I've been trying to figure this seemingly simple problem out for two days and finally decided to post. Hope someone can help.

I simply want to input a decimal number and get the Binary NOT of that number back in decimal. I know I can use the DEC2BIN and BIN2DEC functions to convert but I can't seem to find a way to NOT the binary number. Any ideas??? Just to clarify I want to input say 5 and get back 250

5 > 00000101 > 11111010 > 250 :-?
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Why is 5 = 00000101 - what determines the number of zeroes at the beginning?

If you're always looking at numbers under 256 then surely the answer is always

=255-A1 where your number is in A1

so in your example 255-5 =250

173 > 10101101 > 01010010 > 82

or 255-173 = 82
 
Upvote 0
The bits in that example were arbitrary, however my application requires numbers up to 65535 (16 bits).

In following your solution, I used 65535-A1. The problem now is that excel doesn't seem to like to display over 9 bits.
 
Upvote 0
What about

=2^MAX(8,LEN(DEC2BIN(A1)))-1-A1

edit: no I don't think that will work for you either! Perhaps I'm being a bit dense but I still don't see why 5 = 00000101 and not 00101 or 101 for instance because that will make a differnec to the result.
 
Upvote 0
That is perfect. Thank you. I didn't realize that I could use the MOD function in that way. one of those things that seems so obvious once someone points it out!

The bit length is important as I have a piece of hardware that outputs 16 bit numbers on two wires (one is for 1's, other is for 0's). If the wires are reversed to the main control board, this formula will give me what the controler will see as the number.
 
Upvote 0
Just a quick reply perhaps a more elegant solution would be:

BITXOR(BITLSHIFT(1,8)-1,A1)

In this case 8 represents the number of bits that are inverted by the bitwise not.

So for then for a 16 bit number
BITXOR(BITLSHIFT(1,16)-1,A1)

and then for a 32 bit number
BITXOR(BITLSHIFT(1,32)-1,A1)
 
Upvote 0

Forum statistics

Threads
1,224,222
Messages
6,177,239
Members
452,765
Latest member
Erka Gizli

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top