¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

Re: Data Type Conversion #simplsharp


 
Edited

So it looks like you're converting from a string to short.
Depends on what the data string looks like..

Try these:
//data is some characters representing a hex value
try
{
    data = "FF"
    int i = int.Parse(data, System.Globalization.NumberStyles.HexNumber);
    ushort value = Convert.ToUInt16(i);
}
catch(Exception ex)
{
    CrestronConsole.PrintLine(ex.ToString());
}

//data is prefixed with 0x
try
{
    data = "0xFF"
    int i = Convert.ToInt32(data,16);
    ushort value = Convert.ToUInt16(i);
}
catch(Exception ex)
{
    CrestronConsole.PrintLine(ex.ToString());
}

//data is a string of binary
try
{
    data = "11110000"
    int i = Convert.ToInt32(data,2);
    ushort value = Convert.ToUInt16(i);
}
catch(Exception ex)
{
    CrestronConsole.PrintLine(ex.ToString());
}

//data is a string representing numbers
try
{
    data = "1234"
    int i = Convert.ToInt32(data);
    ushort value = Convert.ToUInt16(i);
}
catch(Exception ex)
{
    CrestronConsole.PrintLine(ex.ToString());
}

Join [email protected] to automatically receive all group messages.