Page 1 of 1

### Binary2decimal & Decimal2binary...???

Posted: Wed Jul 03, 2013 10:16 am
I found this code that i need to work in control basic but i'm having trouble translating...:::

Code: Select all
`Binary to decimal and decimal to binary conversions:----------------------------------------------------Public Function BinaryToDecimal(Binary As String) As LongDim n As LongDim s As Integer For s = 1 To Len(Binary)n = n + (Mid(Binary, Len(Binary) - s + 1, 1) * (2 ^ (s - 1)))Next sBinaryToDecimal = nEnd Function-----------------------------------------------------Public Function DecimalToBinary(DecimalNum As Long) As StringDim tmp As StringDim n As Longn = DecimalNumtmp = Trim(Str(n Mod 2))n = n \ 2Do While n <> 0tmp = Trim(Str(n Mod 2)) & tmpn = n \ 2LoopDecimalToBinary = tmpEnd Function`

Any help is greatly appreciated.

Robert
.

### Re: Binary2decimal & Decimal2binary...???

Posted: Thu Jul 04, 2013 8:26 am
Hi Robert

Have you tried using the BSTR() and the BIN\$() functions to convert Binary->Decimal and Decimal->Binary?

Or do you have other reasons for wanting to translate te functions to Control Basic?

Best regards

Andries

### Re: Binary2decimal & Decimal2binary...???

Posted: Thu Jul 04, 2013 7:51 pm
Thanks for pointing that out to me Andries,

I must have read that a half a dozen times and never really understood what it meant.
You can tell the manual was written by an engineer, seeing it from an engineers perspective.
Don't get me wrong, Daniel is a fine engineer, after all he created the EzSBC1 and its language.
But, he can't see it from layman's terms for the newbie like me.

BIN\$
BIN\$ is short for binary-input-string and is used for Decimal-to-Binary conversion. ...

And maybe a snippet of real-world code to show the syntax...???
There are several commands in the manual that need this...

Robert
.

### Re: Binary2decimal & Decimal2binary...???

Posted: Thu Jul 04, 2013 10:23 pm
I can understand your frustration as a newbie enthusiast Robert. I am a "non-technical" enthusiast who also finds it difficult sometimes to get to grips with some of the descriptions and syntax in the manual. But, for me deciphering and researching some of the engineering speak is part of the fun. I also have the advantage of having some previous programming experience. (I'm not good at it, but enjoy it)

I agree that a brief example for each of the instructions and functions in the manual will help to make the syntax and application clearer.

Personally, my understanding of the BIN\$ function can be described a follows:
Code: Select all
`BIN\$ (<value>,<digits>)The BIN\$ function converts an integer decimal <value> to its binary equivalent and returns the result as a character string. The number of binary digits  in the string (0s and 1s) is specified by <digits>.Negative <digits> is big-endian, positive <digits> is little endian. This is the inverse function of BSTR. Example: PRINT BIN\$(66,8) - prints 01000010`

If you have any problems in future, please post them on the forum. I will try to help, if I can.

Enjoy!!!

Best regards

Andries

### Re: Binary2decimal & Decimal2binary...???

Posted: Sat Jul 13, 2013 4:08 pm
THANK YOU! Andries...

That is a perfect explanation on how to use BIN\$.
Now that is easy to understand.
Daniel should hire you to write his manual.

I have another issue with SERINP\$.
I can't figure out how to use it based on the manual.