bin$

New to FreeBASIC? Post your questions here.
Post Reply
Aerthe
Posts: 249
Joined: May 30, 2005 20:44
Location: Here
Contact:

bin$

Post by Aerthe »

I found this function on the wiki, and i'm trying to make a program that will change a number into a binary value

Code: Select all

input "Type a number here: ", msg$
print bin$(msg$)
sleep
It says there's an error on the second line

Any ideas?
DrV
Site Admin
Posts: 2116
Joined: May 27, 2005 18:39
Location: Midwestern USA
Contact:

Post by DrV »

The argument to BIN must be an integer, not a string. Try this:

Code: Select all

input "Type a number here: ", msg
print bin$(msg)
sleep
Assuming you haven't changed the default data type, that will work (you should really declare your variables, though).[/code]
Aerthe
Posts: 249
Joined: May 30, 2005 20:44
Location: Here
Contact:

Post by Aerthe »

So $ defines a string...

What about the other data types?
jofers
Posts: 1525
Joined: May 27, 2005 17:18

Post by jofers »

The suffixes are a throwback to the dos days, but I would recommend DIMming all your variables. Nonetheless:

$ - String
# - Double
% - Integer
& - Long
! - Single
Aerthe
Posts: 249
Joined: May 30, 2005 20:44
Location: Here
Contact:

Post by Aerthe »

Code: Select all

do
 input "Type in number", nmbr%
 print bin$(nmbr%)
loop
So that would make it so it can only be an integer?
whitetiger0990
Posts: 92
Joined: May 27, 2005 12:34
Location: Universe, Milky Way, Sol III, North-East Hemisphere, North America, USA, ., Chair
Contact:

Post by whitetiger0990 »

That'd make whatever you input be an integer. So if you enter 2.2 nmbr% would equal 2.
Aerthe
Posts: 249
Joined: May 30, 2005 20:44
Location: Here
Contact:

Post by Aerthe »

cool

Code: Select all

do
 input "Type in number", nmbr%
 print bin$(nmbr%)
loop
One problem...

Anyway to get this to 'restart' everytime you press enter after it?[/code]
whitetiger0990
Posts: 92
Joined: May 27, 2005 12:34
Location: Universe, Milky Way, Sol III, North-East Hemisphere, North America, USA, ., Chair
Contact:

Post by whitetiger0990 »

mm? what do you mean?
Post Reply