Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- OPTION BASE 0
- INPUT "text file in current folder: ", name$
- name$ = _CWD$ + "\" + name$
- OPEN name$ FOR BINARY AS #1
- size = LOF(1)
- PRINT size
- DIM bytes(size) AS _UNSIGNED _BYTE
- DIM char AS _UNSIGNED _BYTE
- GET #1, , bytes()
- length = size
- FOR I = 0 TO size - 1
- char = bytes(I)
- IF char >= 128 THEN
- length = length + 1
- END IF
- NEXT
- spot = 0
- DIM newbytes(length) AS _UNSIGNED _BYTE
- FOR I = 0 TO size - 1
- char = bytes(I)
- IF char < 128 THEN
- newbytes(spot) = char
- PRINT char; " became "; char; "!"
- END IF
- IF char >= 128 THEN
- PRINT char; " became "; char \ 64 + &B11000000; " and "; char MOD 64 + &B10000000
- newbytes(spot) = char \ 64 + &B11000000
- spot = spot + 1
- newbytes(spot) = char MOD 64 + &B10000000
- END IF
- spot = spot + 1
- NEXT
- PUT #1, 1, newbytes()
- FUNCTION Bin$ (number&)
- IF number& = 0 THEN EXIT FUNCTION
- DO
- remain% = ABS(number& MOD 2) ' remainder is used to create binary number
- number& = number& \ 2 ' move up one exponent of 2 with integer division
- Bin2$ = LTRIM$(STR$(remain%)) ' make remainder a string number
- Binary$ = Bin2$ + Binary$ ' add remainder to binary number
- LOOP UNTIL number& = 0
- Bin$ = Binary$ 'binary result
- END SUB
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement