卷序列号如何用于序列号 [英] how a volume serial number is used for a serial

查看:216
本文介绍了卷序列号如何用于序列号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个问题要问.如何或可能如何将卷序列号从十六进制转换为十进制,然后进行一些修改以生成序列号的一部分.我有如下示例:

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.

推荐答案

您的问题是将十六进制和十进制视为数据类型,因此转换"了.您无法转换",因为没有要转换的内容.您只能使用一种整数类型.十六进制和十进制只是它的字符串表示形式.

看来您需要在整数中使用单独的字节或半字节.
对于字节,这很容易.使用64位结构代替64位整数:

You problem is thinking as hex and decimal as of data types, hence "convert". You cannot "convert" because there is nothing to convert. There is only one integer type your working with. Hex and decimal are only string presentations of it.

It looks like you need to work with separate bytes or semi-bytes in your integer.
For bytes, this is easy. Instead of your 64-bit integer, use 64-bit structure structure:

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);
}



您仍然可以使用字节,并且可以随字节一起使用半字节.

—SA



You still work with bytes and manipulate with semi-bytes withing the byte.

—SA


这篇关于卷序列号如何用于序列号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆