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