Author Topic: Strange things are afoot at the Circle K  (Read 5403 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Strange things are afoot at the Circle K
« Reply #15 on: March 21, 2020, 03:59:45 pm »
Let's say you have a top secret job as a James Bond super spy.  One of your pieces of technology is a notepad on which you can write up to eight passwords on any given page, but afterwards, once you rip that page out, it automatically flies out of the notepad, using nanomachines, and delivers itself to your bosses...

Now, you write one word on a page, rip it out, it flies off...
You write eight words to a page, rip it out, it flies off...

This is basically _BIT in memory. 

Bits are stored *INSIDE* bytes (just like you'd store a word on a single James Bond notepad page).  You can store 8 bits in one byte (just as you could write 8 words on that page before ripping it off), but those bits are *ALWAYS* stored in bytes...

DIM X AS _BIT is stored in the smallest memory unit available -- a single BYTE.  (Honestly speaking, I don't even think QB64 should even allow this type of usage as the overhead is inefficient and there's no single positive that comes from using it.)

...

So when is it useful to use _BIT??

In a large array to save memory.

DIM X AS BIT uses a byte to store its data.
DIM X(1 TO 8) uses a byte to store its data as well.  (A byte can hold up to 8 bits.)

So if you need to DIM Foo(8000000) AS BIT, you'll use 1000000 bytes of memory (or disk space), rather than the 8000000 you would need with a BYTE variable type.

*********************

Think of it as similar to:

A notebook is similar to total memory.
A page is the smallest unit you can write on, like a byte.
A word is a partial unit which makes up that page, like a bit makes up portion of a byte.

You can't write a word without scribbling it on a page, just as you can't save a BIT without putting it in a BYTE. 
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

FellippeHeitor

  • Guest
Re: Strange things are afoot at the Circle K
« Reply #16 on: March 21, 2020, 04:01:28 pm »
A _byte uses a byte, a _bit uses 4 bytes.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Strange things are afoot at the Circle K
« Reply #17 on: March 21, 2020, 04:26:53 pm »
A _byte uses a byte, a _bit uses 4 bytes.

But an array of 8000000 bytes uses 8000000 bytes.  An array of 8000000 bits uses 1000003 bytes.  8 bits compress into one byte, with the descriptor adding a little overhead. 

Arrays are the only place where it's advantageous to use bits.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!