hey guys, I’m having a bit of a problem. In the full blown .net framework you can do a .ToString(“X2”) format and it works just fine. However when I try this in the .net MicroFramework it throws up an error.
// this code works fine in the regular framework but not in netmf
int y = 13;
Debug.Print(y.ToString("X2"));
@ hobeau
If that the case you can either write your own conversion method to do so,
or
you can Goggle the web to see if there is something available, for example
using the key words “decimal to hex in C#”…
Sam, that google search unfortunately will probably just lead him to the string format method, if it doesn’t the code would have been written by someone who doesnt know it exists… do you really want code from that someone? haha.
I just made a suggestion to him without having seen his reply yet.
I did not if he is an experience programmer or just start to do some programming.
When he replies may be I got to know what he’s really needed.
And may be able to answer his question better.
That’s all, Mark. I didn’t mean to lead him into the difficult place at all.
Hey guys thanks for all the responses. Yes I’m trying to convert it to Hex. According to Visual Studio intellisense there is a string parameter that can be passed to the .ToString() method and it is called format but I’m guessing that this is a toned down version in the netmf. Looks like I’m going to have to do it the old fashioned way… why does that way always seem harder?
@ hobeau
I was unable to get on to the internet all day yesterday(Saturday).
Glad that you find something that can solve your problem.
that method seem to be far more practical than mine.
using System;
using Microsoft.SPOT;
namespace MFConsoleApplication1
{
public class Program
{
public static void Main()
{
int y = 13;
Utils.toHex(y);
}
}
public class Utils
{
public static void toHex(int n)
{
string r;
int tmp;
try
{
if (n == 0)
{
tmp = 0;
r = tmp.ToString();
Debug.Print(r);
}
else
{
tmp = n % 16;
n = n / 16;
toHex(n);
switch (tmp)
{
case 10:
r = "A";
Debug.Print(r);
break;
case 11:
r = "B";
Debug.Print(r);
break;
case 12:
r = "C";
Debug.Print(r);
break;
case 13:
r = "D";
Debug.Print(r);
break;
case 14:
r = "E";
Debug.Print(r);
break;
case 15:
r = "F";
Debug.Print(r);
break;
default:
r = tmp.ToString();
Debug.Print(r);
break;
}
}
}
catch (Exception ex)
{
Debug.Print(ex.ToString());
}
}
}
}