Count "on" "off" or calculate simple "parity" bits of input

版本 1.0.0.0 (12.3 KB) 作者: James Tursa
Three functions to calculate the number of "on", "off", or simple "parity" bits of input
1.2K 次下载
更新时间 2008/8/11

无许可证

Important: You don't have to know anything about mex or c to use this file! Simply follow the instructions below to build the mex files.

Three mex functions are supplied:

onbits is a mex function that counts the number of "on" bits in variable elements. Returns a variable with the same size & structure as the input. Fundamental types (double, single, int8, etc) are replaced with a int8 variable, each element being the number of "on" bits for the corresponding input variable element. For structures and cell arrays, each component or cell is individually counted. Other classes (e.g., vpa, function handles, etc.) are not counted, the return variable is empty. The complex portion of variables are counted as well. Can take any number of inputs as long as there are matching outputs. Valid variable types for input are:

double
single
uint64
int64
uint32
int32
uint16
int16
uint8
int8
char
logical
cell
structure

Building:

>> mex -setup
(then follow instructions to select a C compiler of your choice)
>> mex onbits.c

Syntax:

Y = onbits(X)
[Y1 Y2] = onbits(X1,X2)
[Y1 Y2 Y3] = onbits(X1,X2,X3)
: :
etc etc

Note:

For single and double type inputs, onbits counts the actual bits in the floating point representation of the number. onbits does *not* count the bits in the equivalent integer representation of the number. For example:

onbits(int8(-1)) will give a result of 8 (all bits set "on"), whereas onbits(-1) will give a result of 11, since that is the number of "on" bits in the double floating point representation of -1.

--------------------

offbits is similar to onbits, but counts the number of "off" bits instead of "on" bits.

Building:

>> mex -setup
(then follow instructions to select a C compiler of your choice)
>> mex offbits.c

Syntax:

Y = offbits(X)
[Y1 Y2] = offbits(X1,X2)
[Y1 Y2 Y3] = offbits(X1,X2,X3)
: :
etc etc

--------------------

paritybits is similar to the previous two functions, but calculates simple even or odd parity.

Building:

>> mex -setup
(then follow instructions to select a C compiler of your choice)
>> mex paritybits .c

Syntax:

Y = paritybits (X)
[Y1 Y2] = paritybits (X1,X2)
[Y1 Y2 Y3] = paritybits (X1,X2,X3)
: :
etc etc

引用格式

James Tursa (2024). Count "on" "off" or calculate simple "parity" bits of input (https://www.mathworks.com/matlabcentral/fileexchange/21025-count-on-off-or-calculate-simple-parity-bits-of-input), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R2007a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Logical 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.0.0.0