read BITS in qbasic!!! - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

read BITS in qbasic!!!

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



Sign In or Register to comment.