What programming languages have a bit as variable type?

Discuss whatever you want here--both QB and non-QB related. Anything from the DEF INT command to the meaning of life!

Moderators: Pete, Mods

Post Reply
User avatar
Codemss
Veteran
Posts: 124
Joined: Sun Jun 24, 2007 6:49 am
Location: Utrecht, The Netherlands
Contact:

What programming languages have a bit as variable type?

Post 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.
Check out my site: <a href="http://members.lycos.nl/rubynl">Click here</a>
Hope you like it. Send some feedback if you want: <a href="mailto:basicallybest@live.nl">Mail me</a>
Codemss, before known as RubyNL
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post 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.
User avatar
Codemss
Veteran
Posts: 124
Joined: Sun Jun 24, 2007 6:49 am
Location: Utrecht, The Netherlands
Contact:

Post by Codemss »

Too bad... So I still have to make byte-to-bit LUTs, and 8-bits-to-byte LUTs.
Ok thanks.
Greets,

Codemss
Check out my site: <a href="http://members.lycos.nl/rubynl">Click here</a>
Hope you like it. Send some feedback if you want: <a href="mailto:basicallybest@live.nl">Mail me</a>
Codemss, before known as RubyNL
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Why not have it?

Post 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
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

I'm wondering who you refer to when you say "does not code anymore"...
User avatar
Mentat
Veteran
Posts: 409
Joined: Tue Aug 07, 2007 3:39 pm
Location: NC, US

Post 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.
For any grievances posted above, I blame whoever is in charge . . .
User avatar
Codemss
Veteran
Posts: 124
Joined: Sun Jun 24, 2007 6:49 am
Location: Utrecht, The Netherlands
Contact:

Post 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.
Check out my site: <a href="http://members.lycos.nl/rubynl">Click here</a>
Hope you like it. Send some feedback if you want: <a href="mailto:basicallybest@live.nl">Mail me</a>
Codemss, before known as RubyNL
NaTeDoGG
Newbie
Posts: 7
Joined: Tue Sep 18, 2007 1:16 pm

Post by NaTeDoGG »

A bit has two values, 1 or 0. Many languages (eg, Java) have a boolean type.
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

The Boolean type uses a full byte of memory though.
Patz QuickBASIC Creations
Veteran
Posts: 399
Joined: Wed Mar 02, 2005 9:01 pm
Location: Nashville, Tennessee
Contact:

Post 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.
Post Reply