[Mono-list] how to use 'Conversions.ToInteger' in mono?
Josh Hammond
jhammond at external.fwmail.org
Sat Jun 21 06:04:23 EDT 2008
Hey guys.
I am trying, for the first time, to port a win c# application to a linux
system.
The code is used to access a usb sensor that acts as a rs-232 device, so I
figured out that it is something doable even on linux.
But I also need to perform a binary->decimal conversion.
When working in MS environment I just used
Microsoft.VisualBasic.CompilerServices which, AFAIK, isn't available in
mono.
The function I need to port is:
private static double Bin2Dec(String strBin)
{
try
{
double lDec = 0.0;
if (strBin == null || strBin.Length == 0)
strBin = "0";
double lCount = Strings.Len(strBin);
double t_double = lCount;
for (double i = 1.0; i <= t_double; i++)
{
lDec += Conversions.ToInteger(Strings.Left(strBin, 1))
* Math.Pow(2.0, (double)(Strings.Len(strBin) - 1));
strBin = Strings.Right(strBin, Strings.Len(strBin) - 1);
}
return lDec;
}
catch (Exception) { }
return double.MinValue;
}
Anyone has any suggestions on how to implent this in a way that works on
linux?
Thanks
Josh
More information about the Mono-list
mailing list