Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
21
Добавлен:
11.10.2020
Размер:
3.39 Mб
Скачать

336 The UTIL.LIB Library

Bit/byte functions

k:=BCD_TO_INT(97);

(*

Result

is 151 *)

l:=BCD_TO_INT(100);

(*

Error!

Output: 255 *)

14.3 Bit/byte functions

14.3.1EXTRACT

Inputs to this function are a DWORD X, as well as a BYTE N. The output is a BOOL value, which contains the content of the Nth bit of the input X, whereby the function begins to count from the zero bit.

Examples in ST:

FLAG:=EXTRACT(X:=81, N:=4);(* Result : TRUE, because 81 is binary 1010001, so the 4th bit is 1 *)

FLAG:=EXTRACT(X:=33, N:=0);(* Result : TRUE, because 33 is binary 100001, so the bit '0' is 1 *)

14.3.2PACK

This function is capable of delivering back eight input bits B0, B1, ..., B7 from type BOOL as a BYTE.

The function block UNPACK is closely related to this function.

14.3.3PUTBIT

The input to this function consists of a DWORD X, a BYTE N and a

BOOLean value B.

PUTBIT sets the Nth bit from X on the value B, whereby it starts counting from the zero bit.

Example in ST:

A:=38;

(* binary 100110

*)

 

B:=PUTBIT(A,4,TRUE);

(* Result :

54

=

2#110110

*)

C:=PUTBIT(A,1,FALSE);

(* Result :

36

=

2#100100

*)

14.3.4UNPACK

UNPACK converts the input B from type BYTE into 8 output variables

B0,...,B7 of the type BOOL, and this is the opposite to PACK.

Example in FBD:

WAGO-I/O-SYSTEM 759 WAGO-I/O-PRO 32

Соседние файлы в папке 759-332