VAL decimal convertion
Author Message
VAL decimal convertion

I want to convert a binary number to decimal (in powerbasic). I'm using this
method. Say b\$ is the binary num in string form and a is to be the converted
decimal:
a& = VAL("&B0" + b\$)
The problem is b\$ is 32 digits long and all this method returns is 0. What can
I do or how can I change this to get it to convert to the proper decimal value?
Thanks,

www.webworksinnovations.com

Mon, 01 Dec 2003 03:46:18 GMT
VAL decimal convertion
Works in PB/CC

FUNCTION PBMAIN ()
binarme\$ = "01111111111111111111111111111111111"  '35 binary digits
PRINT VAL ("&b" + binarme\$)
WAITKEY\$
END FUNCTION

' result  17179869183

Er, I hope that *is* the right answer!

Doesn't work in QB because QB doesn't recognize binary numbers,
or at least not the &b format.

Good luck.

Quote:

>I want to convert a binary number to decimal (in PowerBasic). I'm using this
>method. Say b\$ is the binary num in string form and a is to be the converted
>decimal:
>a& = VAL("&B0" + b\$)
>The problem is b\$ is 32 digits long and all this method returns is 0. What can
>I do or how can I change this to get it to convert to the proper decimal value?
>Thanks,

>www.webworksinnovations.com

--
cheers
Jonathan Berry
http://www.islandnet.com/~jberry/      to know more than you want

Mon, 01 Dec 2003 11:43:57 GMT
VAL decimal convertion

Quote:
>I want to convert a binary number to decimal (in PowerBasic). I'm using this
>method. Say b\$ is the binary num in string form and a is to be the converted
>decimal:
>a& = VAL("&B0" + b\$)
>The problem is b\$ is 32 digits long and all this method returns is 0. What can
>I do or how can I change this to get it to convert to the proper decimal value?
>Thanks,

>www.webworksinnovations.com

This seems to work in PB3.5. Make sure there are no spurious spaces in
the input string. A leading space (or an alpha!) will kill it.

John

Mon, 01 Dec 2003 12:44:08 GMT

 Page 1 of 1 [ 3 post ]

Relevant Pages