[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_content.php on line 1014: Undefined array key 3
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_content.php on line 1014: Undefined array key 3
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions_content.php on line 1014: Undefined array key 3
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4130: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3009)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4130: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3009)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4130: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3009)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4130: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3009)
Controlling your World the Easy Way • Binary2decimal & Decimal2binary...???
Page 1 of 1

Binary2decimal & Decimal2binary...???

Posted: Wed Jul 03, 2013 10:16 am
by RBSe
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 Long
Dim n As Long
Dim s As Integer 
For s = 1 To Len(Binary)
n = n + (Mid(Binary, Len(Binary) - s + 1, 1) * (2 ^ (s - 1)))
Next s

BinaryToDecimal = n
End Function

-----------------------------------------------------

Public Function DecimalToBinary(DecimalNum As Long) As String
Dim tmp As String
Dim n As Long

n = DecimalNum

tmp = Trim(Str(n Mod 2))
n = n \ 2

Do While n <> 0
tmp = Trim(Str(n Mod 2)) & tmp
n = n \ 2
Loop

DecimalToBinary = tmp
End Function

Any help is greatly appreciated.

Robert
.

Re: Binary2decimal & Decimal2binary...???

Posted: Thu Jul 04, 2013 8:26 am
by Andries Pretorius
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
by RBSe
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.
What it should read is:

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
by Andries Pretorius
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
by RBSe
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.
I'll start a new thread.

Robert
.