Code: (Select All)
SCREEN _NEWIMAGE(800, 600, 32)
FOR i = 0 TO 25 'Print A to Z, from the alphabet
text$ = text$ + CHR$(65 + i)
a$ = B256to128(text$)
PRINT "B128: "; a$;
LOCATE , 40
b$ = B128to256(a$)
PRINT "B256: "; b$
SLEEP
NEXT
_DELAY 2
END
FUNCTION B256to128$ (text$)
l = 8 * LEN(text$)
DIM A(1 TO l) AS _UNSIGNED _BIT, b AS _UNSIGNED _BYTE
'convert the text to the 8 bit array
FOR i = 1 TO LEN(text$)
b = ASC(text$, i)
p = (i - 1) * 8 + 1
FOR j = 0 TO 7
IF b AND (2 ^ j) THEN A(p + j) = 1 ELSE A(p + j) = 0
NEXT
NEXT
'convert the array to 7bit strings
FOR i = 1 TO l STEP 7
b = 0
FOR j = 6 TO 0 STEP -1
IF i + j < l THEN
IF A(i + j) THEN b = b + (2 ^ j)
END IF
NEXT
b = b + 45
t$ = t$ + CHR$(b)
NEXT
IF LEN(t$) MOD 8 <> 0 AND RIGHT$(t$, 1) = "-" THEN t$ = LEFT$(t$, LEN(t$) - 1)
B256to128 = t$
END FUNCTION
FUNCTION B128to256$ (text$)
l = 7 * LEN(text$)
DIM A(1 TO l) AS _UNSIGNED _BIT, b AS _UNSIGNED _BYTE
'convert the text to the 8 bit array
FOR i = 1 TO LEN(text$)
b = ASC(text$, i) - 45
FOR j = 0 TO 6
p = p + 1: IF p > l THEN EXIT FOR
IF b AND (2 ^ j) THEN A(p) = 1 ELSE A(p) = 0
NEXT
NEXT
'convert the array to 8bit strings
p = 0
FOR i = 1 TO l STEP 8
b = 0
FOR j = 0 TO 7
p = p + 1
IF p > l THEN EXIT FOR
IF A(p) THEN b = b + (2 ^ j)
NEXT
t$ = t$ + CHR$(b)
NEXT
B128to256 = t$
END FUNCTION