如何将 5 位十进制值表示为 24 位值?
How to represent a 5 digit decimal value as a 24 bit value?
我正在尝试转换一个 5 位十进制值(范围从 00001 到 99999),并以某种方式将其表示为一个分成 3 个字节的 24 位值,但我已经尝试了我知道的所有转换和位移策略,但请保留卡住了:/
示例:十进制值为 12345,我需要发送 3 个十六进制值 [aa][bb][cc],其中包括:
[aa] - 最不重要 | [bb] - 中间| [cc] - 最重要的
我希望我没有陷入困境,并且有一个简单的答案,在此先感谢!
尝试以下操作:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Decimal number = new Decimal() { number = 12345 };
string output = number.ToString();
}
}
public class Decimal
{
public int number { get; set; }
public override string ToString()
{
string output = string.Format("[{0}][{1}][{2}]",
(number & 0xFF).ToString("X2"),
((number >> 8) & 0xFF).ToString("X2"),
((number >> 16) & 0xFF).ToString("X2"));
return output;
}
}
}
我正在尝试转换一个 5 位十进制值(范围从 00001 到 99999),并以某种方式将其表示为一个分成 3 个字节的 24 位值,但我已经尝试了我知道的所有转换和位移策略,但请保留卡住了:/
示例:十进制值为 12345,我需要发送 3 个十六进制值 [aa][bb][cc],其中包括:
[aa] - 最不重要 | [bb] - 中间| [cc] - 最重要的
我希望我没有陷入困境,并且有一个简单的答案,在此先感谢!
尝试以下操作:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Decimal number = new Decimal() { number = 12345 };
string output = number.ToString();
}
}
public class Decimal
{
public int number { get; set; }
public override string ToString()
{
string output = string.Format("[{0}][{1}][{2}]",
(number & 0xFF).ToString("X2"),
((number >> 8) & 0xFF).ToString("X2"),
((number >> 16) & 0xFF).ToString("X2"));
return output;
}
}
}