I need to make a formula that gives you the truth table for a variable number of columns.
Example
Replace the FirstCell with a static reference to the cell that contains the first 2^1 value e.g. $D$1 for a 4-bit table (16 values) and autofill to the rest of the grid (in the example A1:D16)
=IF(MOD(ROW()-ROW(FirstCell),POWER(2, ((COLUMN() - COLUMN(FirstCell)) * -1) + 1)) >= (POWER(2, ((COLUMN() - COLUMN(FirstCell)) * -1) + 1) / 2),1,0)
The logic behind this is:
If the current row modulus 2 power current column (* -1 as the first value is in the last column and + 1 because it starts from 0) is greater or equal to half of 2 power current column, put the value as 1, else put the value as 0.
The current recommended answer did not work for me. For a simpler method, I'd recommend the following formula:
=IF(MOD(FLOOR((ROW()-ROW(TopRight))/(2^(COLUMN(TopRight)-COLUMN())), 1),2)=0,0,1)
Where TopRight
is the top right cell of the truth table.
For instance, if you're creating a truth table with 8 entries that starts in A3
, replace TopRight
with $H$3
, then drag the formula across and down.
A basic explanation of what's going on: In truth tables, the rows alternate 1 or 0 every 2 ^ n
number of rows, where n
is the the number of columns that the given column is away from the rightmost column.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With