Some time ago I was programming with encoding LZW-compression. This was very difficult because you can't read bits in qbasic. On the internet there are many GIF-encoders that are coded in qbasic (pretty cool I guess). These program can read BITS (GIF-files use LZW compression to reduce on file space!!).
There are many people who also want to read and store BITs in files. For all those people I made the following sub files. If you find some errors or malfunctions, please reply on this message!
If you want more information about this subject you can also reply on this message!
code:
---
declare sub getbits (numberofbits)
declare sub putbits (numberofbits, value)
sub getbits (numberofbits)
shared bifferbit
shared value
static byte as string *1
value = 0
for bit = 0 to numberofbits - 1
if bufferbit = 8 or bufferbit = 0 then
get
#1, , byte
bufferbit = 0
end if
if asc(byte) and 2 ^ bufferbit then
value = value + 2 ^ bit
end if
bufferbit = bufferbit + 1
next bit
end sub
sub putbits (numberofbits, value)
shared bufferbit
shared buffervalue
static byte as string * 1
for bit = 0 to numberofbits - 1
if value and 2 ^ bit then
buffervalue = buffervalue + 2 ^ bufferbit
end if
bufferbit = bufferbit + 1
if bufferbit = 8 then
byte = chr$(buffervalue)
put
#1, , byte
bufferbit = 0
end if
next bit
end sub
---
That's all folks!
regards,
MightyM