Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
43
Task/Bitwise-IO/BBC-BASIC/bitwise-io.basic
Normal file
43
Task/Bitwise-IO/BBC-BASIC/bitwise-io.basic
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
file$ = @tmp$ + "bitwise.tmp"
|
||||
test$ = "Hello, world!"
|
||||
|
||||
REM Write to file, 7 bits per character:
|
||||
file% = OPENOUT(file$)
|
||||
FOR i% = 1 TO LEN(test$)
|
||||
PROCwritebits(file%, ASCMID$(test$,i%), 7)
|
||||
NEXT
|
||||
PROCwritebits(file%, 0, 0)
|
||||
CLOSE #file%
|
||||
|
||||
REM Read from file, 7 bits per character:
|
||||
file% = OPENIN(file$)
|
||||
REPEAT
|
||||
ch% = FNreadbits(file%, 7)
|
||||
VDU ch%
|
||||
UNTIL ch% = 0
|
||||
PRINT
|
||||
CLOSE #file%
|
||||
END
|
||||
|
||||
REM Write n% bits from b% to file f% (n% = 0 to flush):
|
||||
DEF PROCwritebits(f%, b%, n%)
|
||||
PRIVATE a%, c%
|
||||
IF n% = 0 BPUT #f%,a% : a% = 0 : c% = 0
|
||||
WHILE n%
|
||||
IF c% = 8 BPUT #f%,a% : a% = 0 : c% = 0
|
||||
n% -= 1
|
||||
c% += 1
|
||||
IF b% AND 1 << n% THEN a% OR= 1 << (8 - c%)
|
||||
ENDWHILE
|
||||
ENDPROC
|
||||
|
||||
REM Read n% bits from file f%:
|
||||
DEF FNreadbits(f%, n%)
|
||||
PRIVATE a%, c% : LOCAL v%
|
||||
WHILE n%
|
||||
IF c% = 0 a% = BGET#f% : c% = 8
|
||||
n% -= 1
|
||||
c% -= 1
|
||||
v% = v% << 1 OR (a% >> c%) AND 1
|
||||
ENDWHILE
|
||||
= v%
|
||||
Loading…
Add table
Add a link
Reference in a new issue