如何将5位十进制值表示为24位值? [英] How to represent a 5 digit decimal value as a 24 bit value?
本文介绍了如何将5位十进制值表示为24位值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试转换5位数的十进制值(范围从00001到99999),并以某种方式将其表示为拆分为3个字节的24位值,但是尝试了我知道的每种转换和移位策略,但一直陷于困境:/
I'm trying to convert a 5 digit decimal value (ranging from 00001 to 99999) and somehow represent it as a 24-bit value split into 3 bytes but have tried every conversion and bitshift tactic I know, but keep getting stuck :/
示例:十进制值为12345,我需要发送3个十六进制值[aa] [bb] [cc],其中包括:
Example: decimal value is 12345, and I need to send 3 hex values [aa][bb][cc], which would consist of:
[aa]-最低有效|[bb]-中|[cc]-最重要
[aa] - least significant | [bb] - middle | [cc] - most significant
我希望我不会烦恼,并且有一个简单的答案,在此先谢谢您!
I'm hoping I'm not in over my head and that there is a simple answer, thanks in advance!
推荐答案
尝试以下操作:
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位十进制值表示为24位值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文