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)
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)
I always have to convert a cell to binary then perform the operations manually (bit-by-bit)... like this:
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
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
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
how can i do bitwise (binary) operations (AND, OR, XOR)