-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBYTES.BAS
77 lines (61 loc) · 1006 Bytes
/
BYTES.BAS
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
71
72
73
74
75
76
DECLARE FUNCTION byte$ (num%)
DECLARE FUNCTION nospc$ (a$)
'init
CLS
COLOR 15
PRINT "File Bytes"
COLOR 7
PRINT "----------"
PRINT
'get details
COLOR 14
INPUT "File name"; fsrc$
PRINT
'open file
OPEN "B", #1, fsrc$
length& = LOF(1)
DIM fileByte AS STRING * 1
PRINT "File size = "; length&; " bytes"
PRINT
'get all bytes
FOR i& = 1 TO length&
k$ = ""
WHILE k$ = ""
k$ = INKEY$
WEND
IF k$ = CHR$(27) THEN EXIT FOR
'get byte
GET #1, , fileByte
byt% = ASC(fileByte)
'display
COLOR 7
PRINT "["; i&; "]",
COLOR 14
IF byt% >= 32 THEN PRINT fileByte, ELSE PRINT "...",
COLOR 13
PRINT byt%,
COLOR 12
PRINT HEX$(byt%); "h",
COLOR 11
PRINT byte$(byt%); " b"
NEXT
CLS
CLOSE #1
COLOR 7
SYSTEM
FUNCTION byte$ (num%)
n% = num%
FOR i% = 1 TO 8
IF (n% AND 1) > 0 THEN a$ = "1" + a$ ELSE a$ = "0" + a$
n% = n% \ 2
NEXT
byte$ = LEFT$(a$, 4) + " " + RIGHT$(a$, 4)
END FUNCTION
FUNCTION nospc$ (a$)
b$ = ""
FOR i = 1 TO LEN(a$)
c$ = MID$(a$, i, 1)
IF (c$ <> " ") THEN b$ = b$ + c$
NEXT
nospc$ = b$
END FUNCTION