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;
}
Address separate bytes in this structure.
You you need semi-bytes, its a bit more:
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.
—SA