how can i do bitwise (binary) operations (AND, OR, XOR)

I need to do bitwise (binary) operations such as AND, OR, and XOR. For example, how do I AND 10101000 with 11111000?

MacBook Pro with Retina display, OS X Yosemite (10.10.1)

Posted on Feb 2, 2015 4:06 AM

Reply
3 replies
Sort By: 

Feb 2, 2015 5:51 AM in response to kimchi87

I always have to convert a cell to binary then perform the operations manually (bit-by-bit)... like this:

User uploaded file

B1=MID($A1, COLUMN()−1, 1)

this is shorthand for... select cell B1, then type (or copy and paste from here) the formula:

=MID($A1, COLUMN()−1, 1)


select B1, copy

select cell B2, paste

B3=IF(AND(B1="1", B2="1")=TRUE, 1, 0)




select cell B1 thru B3, copy

select cell B1 thru I3, paste


this performs the and operation

Reply

Feb 2, 2015 7:53 AM in response to kimchi87

For AND, you can also use the SUBSTITUTE function.


For example, with 10101000 in A1 and 11111000 in A2, use:


=1×SUBSTITUTE(SUBSTITUTE(A1+A2,1,0),2,1)


Result:


10101000


Or even shorter, try this:


=SUBSTITUTE(A1+A2,1,0)÷2


SG

Reply

Feb 2, 2015 9:34 AM in response to kimchi87

for OR, with 10101000 in A1 and 11111000 in A2, try:


=1×SUBSTITUTE(A1+A2,2,1)


Result: 11111000


and for XOR, try:

=1×SUBSTITUTE(A1+A2,2,0)


Result: 1010000 (missing leading 0)


You can display missing leading zeros by setting the cell's Data Format to 'Numeral System' with Base set to 10 and Places to 8, or turn the result into a string with something like this (assuming the result is in A3):


=RIGHT("0000000"&A3,8)


SG

Reply

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

how can i do bitwise (binary) operations (AND, OR, XOR)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.