-
Notifications
You must be signed in to change notification settings - Fork 5
/
BYTE_TO_STRH.EXP
executable file
·70 lines (58 loc) · 1.69 KB
/
BYTE_TO_STRH.EXP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
(* @NESTEDCOMMENTS := 'Yes' *)
(* @PATH := '\/String' *)
(* @OBJECTFLAGS := '0, 8' *)
(* @SYMFILEFLAGS := '2048' *)
FUNCTION BYTE_TO_STRH : STRING(2)
VAR_INPUT
IN : BYTE;
END_VAR
VAR
temp : BYTE;
PT : POINTER TO BYTE;
END_VAR
(*
version 1.3 29 mar. 2008
programmer hugo
tested by tobias
BYTE_TO_STRINGH converts a Byte to a String of Hexadecimal represented by '0' .. '9' and 'A' .. 'F'.
The lowest order Character will be on the right and the high order Character on the left.
*)
(* @END_DECLARATION := '0' *)
(* read pointer to output string *)
PT := ADR(BYTE_TO_STRH);
(* calculate high order hex value *)
temp := SHR(in,4);
(* convert value to hex character *)
IF temp <= 9 THEN temp := temp + 48; ELSE temp := temp + 55; END_IF;
(* write friat character to output string *)
PT^ := temp;
(* calculate low order hex value *)
temp := in AND 2#00001111;
IF temp <= 9 THEN temp := temp + 48; ELSE temp := temp + 55; END_IF;
(* increment pointer and wirte low order character *)
pt := pt + 1;
pt^ := temp;
(* set pointer at the end of the output string and close the string with 0 *)
pt := pt + 1;
pt^:= 0;
(* code before rev 1.2
FOR i := 1 TO 2 DO
X := in AND 2#1111;
IF X <= 9 THEN X := X + 48; ELSE X := X + 55; END_IF;
Cx := CHR(X);
temp := CONCAT(Cx, temp);
in := SHR(in,4);
END_FOR;
BYTE_TO_STRH := temp;
*)
(* revision history
hm 9.6.2007 rev 1.0
original version
hm 11.9.2007 rev 1.1
changed coding for compatibility with twincat, under twincat concat cannot have a function as argument.
hm 15 dec 2007 REV 1.2
changed code for higher performance
hm 29. mar. 2008 rev 1.3
changed STRING to STRING(2)
*)
END_FUNCTION