Advertisement
LBASIC

826_BIT.BAS

Jun 5th, 2023
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QBasic 1.30 KB | Source Code | 0 0
  1. '_|_|_|  826_BIT.BAS
  2. '_|_|_|  This program demonstrates one method of encoding data
  3. '_|_|_|  to conform to low ASCII requirements by turning three
  4. '_|_|_|  8-bit values into four 6-bit values and vice-verse.
  5. '_|_|_|  No warrantees or guarantees are given or implied.
  6. '_|_|_|  Released to   PUBLIC DOMAIN   by Kurt Kuzba.  (6/1/96)
  7. DECLARE FUNCTION ENCODE$ (Bytes3$)
  8. DECLARE FUNCTION UNCODE$ (Bytes4$)
  9. PRINT : PRINT
  10. test$ = CHR$(176) + CHR$(177) + CHR$(178)
  11. PRINT test$, ENCODE$(test$), UNCODE$(ENCODE$(test$))
  12. test$ = CHR$(254) + CHR$(219) + CHR$(129)
  13. PRINT test$, ENCODE$(test$), UNCODE$(ENCODE$(test$))
  14. test$ = CHR$(17) + CHR$(21) + CHR$(7)
  15. PRINT test$, ENCODE$(test$), UNCODE$(ENCODE$(test$))
  16. test$ = "ABC"
  17. PRINT test$, ENCODE$(test$), UNCODE$(ENCODE$(test$))
  18. '_|_|_|  end 826_BIT.BAS
  19.  
  20. FUNCTION ENCODE$ (Bytes3$)
  21.    Result$ = "": B& = 0
  22.    FOR t% = 3 TO 1 STEP -1
  23.       B& = B& * 256 + ASC(MID$(Bytes3$, t%))
  24.    NEXT
  25.    FOR t% = 1 TO 4
  26.       Result$ = Result$ + CHR$(48 + (B& AND 63)): B& = B& \ 64
  27.    NEXT: ENCODE$ = Result$
  28. END FUNCTION
  29.  
  30. FUNCTION UNCODE$ (Bytes4$)
  31.    Result$ = "": B& = 0
  32.    FOR t% = 4 TO 1 STEP -1
  33.       B& = B& * 64 + ASC(MID$(Bytes4$, t%)) - 48
  34.    NEXT
  35.    FOR t% = 1 TO 3
  36.       Result$ = Result$ + CHR$(B& AND 255): B& = B& \ 256
  37.    NEXT: UNCODE$ = Result$
  38. END FUNCTION
  39.  
  40.  
Tags: qbasic
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement