2 Instruction Descriptions
2-376
NJ-series Instructions Reference Manual (W502)
BitCnt
The BitCnt instruction counts the number of TRUE bits in a bit string.
* If you omit the input parameter, the default value is not applied. A building error will occur.
The BitCnt instruction counts the number of TRUE bits in count string In. The following example is for
when In is BYTE data with a value of BYTE#16#85.
Instruction Name FB/FUN Graphic expression ST expression
BitCnt Bit Counter FUN Out:=BitCnt(In);
Variables
Name Meaning I/O Description Valid range Unit Default
In Count
string
Input String in which to count
TRUE bits
Depends on data type.
--- *
Out Count
result
Output Number of TRUE bits 0 to No. of bits in In
--- ---
Boolean
Bit strings Integers
Real
numbers
Times, durations,
dates, and text strings
BOOL
BYTE
WORD
DWORD
LWORD
USINT
UINT
UDINT
ULINT
SINT
INT
DINT
LINT
REAL
LREAL
TIME
DATE
TOD
DT
STRING
In OK OK OK OK
Out OK
Function
(@)BitCnt
EN ENO
In Out
abc:=BitCnt(BYTE#16#85);
LD ST
BYTE#16#85 abc
BitCnt
EN ENO
In
In
1 0 0 0 1 0 0 1
3
Out = abc
The number of TRUE (1) bits is counted.