View Raw SPL
/*****************************************************************************
* *
* ROWBITS.SPL Copyright (C) 2020 DSP Development Corporation *
* All Rights Reserved *
* *
* Author: Randy Race *
* *
* Synopsis: Sums each row as bits *
* *
* Revisions: 7 Aug 2020 RRR Creation *
* *
*****************************************************************************/
#if @HELP_ROWBITS
ROWBITS
Purpose: Sums each row of a table as bit values.
Syntax: ROWBITS(s)
s - A multi-column series of ones and zeros.
Returns: A single column series of the same length as the input.
Each value of the series is the bit sum of the input rows.
Example:
W1: {{0, 0, 0, 0},
{0, 0, 0, 1},
{0, 0, 1, 0},
{0, 0, 1, 1},
{1, 1, 0, 0}}
W2: rowbits(w1)
W1 contains a 5x4 table of values where each value is a 1
or a 0. Each row is considered a 4 bit binary value where
the MSB is the first column.
W2 contains the series {0, 1, 2, 3, 12}, the bit values of
each row of W1.
Example:
W1: int(rand(3, 10) * 100) > 50
W2: rowbits(w1)
W1 contains a random 3x10 table of values where each value
is a 1 or a 0. Each row is considered a 10 bit binary
value where the MSB is the first column.
W2 contains the series of bit values of each row of W1.
Remarks:
ROWBITS assumes each row contains bit value of 1 or 0 where
the first column is the MSB.
Any number of columns can be processed, each row of an N
column series represents an N bit value.
See Also:
Rowsum
#endif
/* sum bit values of each row */
rowbits(s)
{
if (argc < 1)
{
error(sprintf("%s - input series required", __FUNC__));
}
/* bit values as a row, first column is MSB */
h = transpose(2^(((numcols(s)-1)..-1..0)));
/* multiple each column by bits and sum resulting rows */
h = rowsum(s * h);
return(h);
}