Here is the requirements of my function:
take the following string:
6900460420006149231=13050010300100000
and convert it to the following byte array:
{ 0x37, 0x06, 0x90, 0x04, 0x60, 0x42, 0x00, 0x06, 0x14, 0x92, 0x31, 0xD1, 0x30, 0x50, 0x01, 0x03, 0x00, 0x10, 0x00, 0x00 }
The first byte 0x37 is the original length of the string in binary. The next 10 bytes is the string "6900460420006149231" encoded in bcd format. This is where this gets tricky. Now I need the Hex 'D' to represent the separator(=) between the two fields. You can see the hex in the high nibble of the 12 index in the byte array. The rest of the byte array is the second field "13050010300100000" encoded in bcd format. If the original length is an odd number, I put a leading zero to pad the first half-byte of unused data.
I don't expect a full implementation from anyone so lets break this down and address where I am having trouble. Lets say I have:
byte[] field1Bytes = { 0x06, 0x90, 0x04, 0x60, 0x42, 0x00, 0x06, 0x14, 0x92, 0x31 }
byte[] field2Bytes = { 0x01, 0x30, 0x50, 0x01, 0x03, 0x00, 0x10, 0x00, 0x00 }
byte separator = 13; // D 0x0D
If I simply use Array.Copy, I would end up with:
{ 0x06, 0x90, 0x04, 0x60, 0x42, 0x00, 0x06, 0x14, 0x92, 0x31, 0x0D, 0x01, 0x30, 0x50, 0x01, 0x03, 0x00, 0x10, 0x00, 0x00 }
The above byte array isn't quite what I need.. Any idea on how I could implement the following function to get me closer to what I am trying to achieve:
byte[] ShiftLeftAndCombine(byte[] b1, byte[] b2)
where
ShiftLeftAndCombine({0x0d}, {0x01, 0x30})
would return
{0xd1, 0x30}
- on a side note I realize I need to handle even/odd field lengths to address the actual function I am writing, but let me worry about that =]