I am trying to create a table by iteratively calculating its values using a temporary variable accu
:
samplingRate = 500;
seconds = 0.2;
bits = 16;
maxV = 2.^bits;
freq = 500;
samples = samplingRate * seconds;
accu = 0;
inc = maxV *freq/samplingRate;
res = Table[
accu = accu + inc;
accu = BitAnd[accu, 255];
accu,
{t, 0, samples - 1}
];
ListPlot[res]
res
The line accu = accu + inc;
is interpreted just the way I intended (it increments accu
by inc
. But in the next line, I expect Mathematica to take just the lowest 8 bits of accu
and re-assign that value to accu
. Instead, Mathematica seems to interpret this expression an equation that can be solved for accu
: the first element of the Table is the unevaluated BitAnd function with its two arguments, the next entry is a nested combination of a BitAnd taking the first BitAnd as an argument etc. How can I force Mathematica to simply evaluate BitAnd and assign the result to accu (just like it does in the line above)?
seconds = 0.2;
andmaxV = 2.^bits;
; replace them withseconds = 1/5;
andmaxV = 2^bits;
(ormaxV = BitShiftLeft[1, bits]
). Don't use inexact numbers with functions that expect integers likeBitAnd[]
. $\endgroup$ – J. M.'s ennui♦ Nov 16 '19 at 12:10