New Variable Type .bin

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

New Variable Type .bin

Post by Rook Zimbabwe »

Looking over the variable types list I see a great selection... but I was wondering if we could not add a new variable type solely for Binary numbers?

Is it even possible?

I use a string at the moment... but think it would be faster if it were an actual type!

:D
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

Binary numbers like:

Code: Select all

%1100011
?
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

@Rook
what would you need it for?

in the end, it's only a display issue, not a storing issue.
you can display each and every number in your program in binary format.

displaying a number always means to convert it to a string.
decimal transscription is done automatically for some outputs,
thus you can just "Debug A", but under the hood it's "Debug Str(A)",
and its up to you to "Debug Bin(A)"
input handling also works via Strings,
you can convert a binary string into a value using Val() and adding a preceding "%".

Code: Select all

bin$ = "%"+Bin(170)
Debug bin$

binary.l = Val(bin$)

Debug binary
Debug Bin(binary)
PS:
here some further 'literature' about how to handle bits and what you can do with them:
Bit Twiddling Hacks: http://graphics.stanford.edu/~seander/bithacks.html
Last edited by Kaeru Gaman on Fri Aug 22, 2008 9:22 am, edited 1 time in total.
oh... and have a nice day.
Hurga
Enthusiast
Enthusiast
Posts: 148
Joined: Thu Jul 17, 2003 2:53 pm
Contact:

Post by Hurga »

Hm, for me it seems that he mean just 0 or 1. A variable which stores only one bit.
User avatar
Hroudtwolf
Addict
Addict
Posts: 803
Joined: Sat Feb 12, 2005 3:35 am
Location: Germany(Hessen)
Contact:

Post by Hroudtwolf »

I don't know such a type from other programming languages.
Also boolean types has AFAIK in many languages more than one byte.
Therefore a multiple more than one bit.

Regards

Wolf
Post Reply