Page 1 of 1

What programming languages have a bit as variable type?

Posted: Fri Dec 21, 2007 10:22 am
by Codemss
What programming languages have a "bit" as variable type? I saw QB64 has. This is very useful. In a engine wher eI scroll an large monochrome map. For this, I have to make an array of integers, load them with PEEK and POKE(because they use bytes) and then use a byte-to-bit LUT, and again a 8-bits-tobyte LUT. This is not very practical...

PS Someone told me that you can decalre a variable as a bit in FB(or was it a BYTE?) too, but I'm pretty sure he meant an other language or he made a mistake, because it just doesn't work in FB. It would be a great feature though. Just like SHL and SHR. Very useful.

Posted: Fri Dec 21, 2007 11:51 am
by Nodtveidt
Having a BIT variable type is a tremendously bad idea because it isn't the way the CPU works. The smallest amount of data you can directly access is the byte, and there is no way around this. In order for a BIT variable type to work, a full byte has to be used, leaving seven bits unused. This could add up pretty quickly, and is more than likely the reason why no normal compiler features a bit type...it's terribly wasteful, inefficient, and requires special code in the runtime library to handle it, expanding the final binary size further.

Posted: Sat Dec 22, 2007 6:50 am
by Codemss
Too bad... So I still have to make byte-to-bit LUTs, and 8-bits-to-byte LUTs.
Ok thanks.
Greets,

Codemss

Why not have it?

Posted: Sat Dec 22, 2007 2:32 pm
by burger2227
Apparently there are some uses for it. Serial ports send bits of information and I am sure somebody could use it in other ventures.

What would a person who does not even code anymore use it for N ?

Why would somebody go to the trouble of making one if it did not provide some kind of an advantage? Hmmmmmmmm........

Ted

Posted: Sat Dec 22, 2007 4:42 pm
by Nodtveidt
I'm wondering who you refer to when you say "does not code anymore"...

Posted: Sat Dec 22, 2007 4:50 pm
by Mentat
You can use pieces of numbers. Lets say variable type Byt is 0 through 100. In decimal, you can use place-values for separate numbers, ie 43 can be 4 and 3. Binary would be something like 13 is 3 and 1 (1101:11 01). You can break up numbers into bits. But to manipulate the bits themselves is another matter.

Posted: Mon Dec 24, 2007 5:17 am
by Codemss
Well, it is much easier to use when you can define how much bits you need for one variable. Also it is much easier when you want to do something that's monochronome.

Posted: Wed Jan 16, 2008 2:18 am
by NaTeDoGG
A bit has two values, 1 or 0. Many languages (eg, Java) have a boolean type.

Posted: Wed Jan 16, 2008 5:14 am
by Nodtveidt
The Boolean type uses a full byte of memory though.

Posted: Wed Jan 16, 2008 8:00 pm
by Patz QuickBASIC Creations
In BASIC a boolean/bit type aren't necessary/logical. Smart manipulation of the logical operators (AND, OR, XOR, NOT, IMP) should be enough to get you where you need to be.