Tables – Binary Representation of an Integer

foreachprogrammingtables

Is there a way to get a binary string of an integer calculated by e.g., \pgfmathparse{pow(2,3)} \pgfmathresult such that later on I can use the string digits in a foreach loop like .. if it is '1' do this or if the digit is '0' do that?

I don't need to use the tikz or pgf packages; if there is any other math engine with programming language features, that would be fine, too. My goal is to generate a table atuomatically.

Best Answer

To store the binary representation of an integer in a macro you can use PGF/TikZ \pgfmathdectobase:

\pgfmathdectobase\yourresult{<integer>}{2}

In order to use this in a \foreach loop you would still need add commas between the bits.

Related Question