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,
Brad

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,
>Brad

>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,
>Brad

>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  
 
 [ 3 post ] 

 Relevant Pages 

1. CONVERTION DECIMAL IN PACKED NUMBERS

2. CONVERTION DECIMAL IN PACKED NUMBERS

3. CONVERTION DECIMAL IN PACKED NUMBERS

4. CONVERTION DECIMAL IN PACKED NUMBERS

5. how get decimal.precision and decimal.scale?

6. Decimal Point: How to Write vi′s for different decimal symbols

7. Convert from binary to decimal, hex to decimal etc

8. Decimal can be Binary Too (was decimal or rational)

9. Troubles woith the VAL method

10. VAL for integers

11. VAL - Possible bug?

12. using the val command

 

 
Powered by phpBB® Forum Software