本文介绍了卷序列号如何用于序列号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我有一个问题要问.如何或可能如何将卷序列号从十六进制转换为十进制,然后进行一些修改以生成序列号的一部分.我有如下示例:
Hi
I have a question to ask. How or is it possible to take a volume serial number convert it into decimal from hex and then some how modify it to generate a portion of a serial number. I have and example as follows:
Example 1:
2350214222 -HDD Serial Number converted from Hex
000A0C3B2EE30087 -Activation Code
A B 3 7 -Expiry Date
3 e 8 -Emp amount
000 0C 2E 00 -Corresponds to HDD Volume(2350214222) ?
Example 2:
142598462 -HDD Serial Number converted from Hex 87FE13E
000A0E0BA6C30087 -Activation Code
A B 3 7 -Expiry Date
0 C 8 -Emp amount
000 0E A6 00 -Corresponds to HDD Volume(142598462) ?
任何评论表示赞赏.
Any comments appreciated.
推荐答案
using System.Runtime.InteropServices;
//...
[StructLayout(LayoutKind.Explicit)]
struct VolumeSerialNumberDecoded {
[FieldOffset(0)] byte ExpirationDay;
[FieldOffset(1)] byte Amount; //1-byte shift
//...
//you can define intercepting memory areas: this is like union
}
在此结构中寻址单独的字节.
您需要半字节,还需要更多字节:
Address separate bytes in this structure.
You you need semi-bytes, its a bit more:
//this will work correctly only for lo or hi in 0..F:
static byte ByteFromSemibytes(byte lo, byte hi) {
return (byte)(hi << 4 + lo);
}
static byte GetLoSemibyte(byte value) {
return (byte)(value & 0x0F);
}
static byte GetHiSemibyte(byte value) {
return (byte)((value & 0xF0) >> 4);
}
您仍然可以使用字节,并且可以随字节一起使用半字节.
You still work with bytes and manipulate with semi-bytes withing the byte.
这篇关于卷序列号如何用于序列号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!