EXTRACT (FUN) ¶ FUNCTION EXTRACT : BOOL Returns bit number N of value X Example in ST: FLAG := EXTRACT ( X := 81 , N := 4 ); (* Result : TRUE, because 81 is binary 1010001, so the bit '4' is 1 *) FLAG := EXTRACT ( X := 33 , N := 0 ); (* Result : TRUE, because 33 is binary 100001, so the bit '0' is 1 *) InOut: Scope Name Type Comment Return EXTRACT BOOL The Nth bit of value X Input X DWORD Input value N BYTE Number of the bit to be extracted. Counting starts at 0.
GETBIT (FUN) ¶ FUNCTION GETBIT : BOOL Returns the bit value at position N of value X InOut: Scope Name Type Comment Return GETBIT BOOL Input X LWORD Variable from which the bit is chosen, value has to be unsigned N BYTE The bitnumer 0…(size of datatype)
PACK (FUN) ¶ FUNCTION PACK : BYTE Packs 8 bits into 1 byte InOut: Scope Name Type Comment Return PACK BYTE Value for the input BO .. B7 Input B0 BOOL Input bit 0 B1 BOOL Input bit 1 B2 BOOL Input bit 2 B3 BOOL Input bit 3 B4 BOOL Input bit 4 B5 BOOL Input bit 5 B6 BOOL Input bit 6 B7 BOOL Input bit 7
PUTBIT (FUN) ¶ FUNCTION PUTBIT : DWORD Sets a bit of a DWORD value Example in ST: var1 := 38 ; (* binär 100110 *) var2 := PUTBIT ( A , 4 , TRUE ); (* Result: 54 = 2#110110 *) var3 := PUTBIT ( A , 1 , FALSE ); (* Result: 36 = 2#100100 *) InOut: Scope Name Type Comment Return PUTBIT DWORD Value with the changed bit Input X DWORD Value to be manipulated N BYTE Position of the bit to be changed, starting with 0 B BOOL Value of specified bit
SETBIT (FUN) ¶ FUNCTION SETBIT : BOOL Sets the value of bit at position N of variable X to B InOut: Scope Name Type Comment Return SETBIT BOOL Input X __SYSTEM.AnyType Variable to be modified N BYTE Bitnummer 0…(to size of datatype) B BOOL Desired value of the bit
SWITCHBIT (FUN) ¶ FUNCTION SWITCHBIT : DWORD Switches a bit of a DWORD value See also: PUTBIT and EXTRACT . InOut: Scope Name Type Comment Return SWITCHBIT DWORD Value with the switched bit Input X DWORD Value to be manipulated N BYTE Position of the bit to switch, starting with 0
UNPACK (FB) ¶ FUNCTION_BLOCK UNPACK Converts a byte into 8 bits InOut: Scope Name Type Comment Input B BYTE Input value Output B0 BOOL Output bit 0 B1 BOOL Output bit 1 B2 BOOL Output bit 2 B3 BOOL Output bit 3 B4 BOOL Output bit 4 B5 BOOL Output bit 5 B6 BOOL Output bit 6 B7 BOOL Output bit 7
WORD_AS_BIT (FB) ¶ FUNCTION_BLOCK WORD_AS_BIT Converts an input value of data type WORD into 16 outputs of data type BOOL InOut: Scope Name Type Comment Input W WORD Input value Output B00 BOOL Output bit 0 B01 BOOL Output bit 1 B02 BOOL Output bit 2 B03 BOOL Output bit 3 B04 BOOL Output bit 4 B05 BOOL Output bit 5 B06 BOOL Output bit 6 B07 BOOL Output bit 7 B08 BOOL Óutput bit 8 B09 BOOL Output bit 9 B10 BOOL Output bit 10 B11 BOOL Output bit 11 B12 BOOL Output bit 12 B13 BOOL Output bit 13 B14 BOOL Output bit 14 B15 BOOL Output bit 15
HEX/ASCII Functions ¶ BYTE_TO_HEXinASCII (Function) HEXinASCII_TO_BYTE (Function) WORD_AS_STRING (Function)
BYTE_TO_HEXinASCII (FUN) ¶ FUNCTION BYTE_TO_HEXinASCII : WORD Converts one byte of binary code into one word in HEX code representing its ASCII value The higher bits in the input are represented by the higher byte in the output. Use HEXinASCII_TO_BYTE function for the reverse conversion. InOut: Scope Name Type Comment Return BYTE_TO_HEXinASCII WORD ASCII value as WORD of the input B Input B BYTE Value in binary code