Test number for 2^x in Calc

In many languages you can test (2^x)==y to see if y contains a 4 for example. Or you can pull out a 0 or 4 with (2^2)&y.

Can you help me find this functionality?

Thanks, Dick

Do you mean functions BITAND() and BITOR()?

Thanks for your time. Yes this sounds just right. However BITAND() is not listed in functions and BITAND() returns #NAME? for me in LibreOffice 3.4.3
OOO340m1 (Build:302). Is there an extension to download? Thanks again.

Yes, I didn’t found a description of these functions in the Help too. I stumbled upon them in LibreOffice 4.0.1 (There are description of these functions is in the help of HelpPack )

I installed LibreOffice Version 3.6.5.2 as itsGetting started doc stated it had added BITx as declared in the ODF 1.2 specification." Tested BITAND() and it works fine. However the new LibreOffice download seemed to require Torrent if I didn’t want to build my own downloader. I DID NOT LIKE THE EXPERIENCE OF GETTING RID OF uTORRENT AT ALL! If you prefer to avoid that the text solution works, otherwise BITAND() is cleaner. Thanks to JohnSUN and mariosv.

Use BITAND() to test for binary values. Your version of LibreOffice must be 3.6 or greater.
TRUE=BITAND(4,20) - from JohnSUN
Previous to version 3.6 use this text based test
=NOT(ISERROR(SEARCH(SUBSTITUTE(BASE(4;2);“0”;".")&"$";BASE(109;2)))) using =IF(B3;Formula;0) to prevent a search for 0 returning a TRUE - from mariosv

Comment:
I installed LibreOffice Version 3.6.5.2 as itsGetting started doc stated it had added BITx as declared in the ODF 1.2 specification." The new LibreOffice download seemed to require Torrent if I didn’t want to build my own downloader. I DID NOT LIKE THE EXPERIENCE OF GETTING RID OF uTORRENT AT ALL!

I recently (Version 4.2.0.4) tested =BITAND($B14,4), =BITAND($G17,2^2), and =IF(BITAND($L17,2^2),1,0) which returned 4, 4, and 1. All work depending on the form of the test and desired answer.
Thanks to JohnSUN and mariosv.

Hi @rcw,

I’m not sure what platform you’re using, but you should be able to grab the latest build of LibreOffice on the download page without using bittorrent. Please try clicking on the text that reads Main installer, or (if you’d like to choose a different language or OS) click on Change System, Version or Language.

Thanks!

Looking at the the download page I now see that Main Installer, torrent, and Info are different choices. As they are all inside a big green box I did not notice the different links until you said I should be able to not use torrent. Sigh. Thanks for your time.

As we have 2 topics under this question my answer concerns @rcw’s comment

I DID NOT LIKE THE EXPERIENCE OF GETTING RID OF uTORRENT AT ALL!

I feel that the current button to download LibO or LibO help files is a bit confusing. I also was once confronted with a torrent file and found later accidentally that the download button contains 2 versions:

image description

Depending on where you click you a msi-file or torrent-file download starts.

This is done with Windows version.

An enhancement request is filed. Please feel free to add comments to enable better judgment.
https://bugs.freedesktop.org/show_bug.cgi?id=63287

As “rcw” recently updated this post:
If someone still is using old versions of Calc not containing the bit operation functions for some reason:
=ISODD(QUOTIENT({ValueToTest};{PowerOf2})) is a compact alternative to the formerly suggested text oriented solutions.

Using versions containing the bit functions the formula

=QUOTIENT({ValueToTest};{Base}^{Exponent})-QUOTIENT(CURRENT();{Base}) * {Base}
can still be used where the base for whose powers should be tested is not 2 but another integer number.

Sorry, the last formula was erroneous in the first post of this answer. It was rectified by editing.

Only one equal for comparisons in calc.
You can do:
=(2^2)=4

2^2+2^4=20. I was looking for the test: Does number (example 20) contain a 4? In binary, 00100+10000=10100. I am trying to test for the binary position. This can be used for a mask or as a flag.

Forgive me rcw, I have misunderstood your question.

Next screenshot shows one way to find if a binary is inside other, using the SEARCH() function which allow regular expression, substituting the zeroes with point (any character) adding the “$” (to find at the end).

=NOT(ISERROR(SEARCH(SUBSTITUTE(BASE(4;2);“0”;".")&"$";BASE(109;2))))

image description

Thanks for your time. This text solution works for all but case “0” where it always returns True. If I can’t get a math method running this will work. Thanks again.

A simple solution: =IF(B3;Formula;0), can solve the 0 issue.

Yes, Thank you very much. Dick