Skip to main content
added 4 characters in body
Source Link
ProphetV
  • 711
  • 6
  • 9

If the first two characters are not constant (but are always letters) and the remaining six characters are always numbers, a string like "IO123456" can be packed into 5 bytes by converting the numbers into binary-coded decimal (BCD) format:

IO123456 -> 0x49 0x4f 0x31 0x32 0x33 0x34 0x35 0x36
             |    |      \   /     \   /     \   /
            0x49 0x4f     0x12      0x34      0x56

If there is a limited set of possible identifiers (the first two letters), you can encode these into a number and send that instead (as long as there are no more than 256 combinations), e.g.:

IO -> 0x00
RD -> 0x01
WT -> 0x02
   ...
AB -> 0x10
   ...
ZZ -> 0xff

so that the original string is packed into 4 bytes without any loss of information:

IO123456 -> 0x49 0x4f 0x31 0x32 0x33 0x34 0x35 0x36
              \    /     \   /     \   /     \   /
               0x00       0x12      0x34      0x56

Of course this process can also be reversed to get the original ID string.

If the first two characters are not constant (but are always letters) and the remaining six characters are always numbers, a string like "IO123456" can be packed into 5 bytes by converting the numbers into binary-coded decimal (BCD) format:

IO123456 -> 0x49 0x4f 0x31 0x32 0x33 0x34 0x35 0x36
             |    |      \   /     \   /     \   /
            0x49 0x4f     0x12      0x34      0x56

If there is a limited set of possible identifiers (the first two letters), you can encode these into a number and send that instead (as long as there no more than 256 combinations), e.g.:

IO -> 0x00
RD -> 0x01
WT -> 0x02
   ...
AB -> 0x10
   ...
ZZ -> 0xff

so that the original string is packed into 4 bytes without any loss of information:

IO123456 -> 0x49 0x4f 0x31 0x32 0x33 0x34 0x35 0x36
              \    /     \   /     \   /     \   /
               0x00       0x12      0x34      0x56

Of course this process can also be reversed to get the original ID string.

If the first two characters are not constant (but are always letters) and the remaining six characters are always numbers, a string like "IO123456" can be packed into 5 bytes by converting the numbers into binary-coded decimal (BCD) format:

IO123456 -> 0x49 0x4f 0x31 0x32 0x33 0x34 0x35 0x36
             |    |      \   /     \   /     \   /
            0x49 0x4f     0x12      0x34      0x56

If there is a limited set of possible identifiers (the first two letters), you can encode these into a number and send that instead (as long as there are no more than 256 combinations), e.g.:

IO -> 0x00
RD -> 0x01
WT -> 0x02
   ...
AB -> 0x10
   ...
ZZ -> 0xff

so that the original string is packed into 4 bytes without any loss of information:

IO123456 -> 0x49 0x4f 0x31 0x32 0x33 0x34 0x35 0x36
              \    /     \   /     \   /     \   /
               0x00       0x12      0x34      0x56

Of course this process can also be reversed to get the original ID string.

Described number encoding as BCD (thanks Blrfl)
Source Link
ProphetV
  • 711
  • 6
  • 9

If the first two characters are not constant (but are always letters) and the remaining six characters are always numbers, a string like "IO123456" can be packed into 5 bytes by converting the numbers into binary-coded decimal (BCD) format:

IO123456 -> 0x49 0x4f 0x31 0x32 0x33 0x34 0x35 0x36
             |    |      \   /     \   /     \   /
            0x49 0x4f     0x12      0x34      0x56

If there is a limited set of possible identifiers (the first two letters), you can encode these into a number and send that instead (as long as there no more than 256 combinations), e.g.:

IO -> 0x00
RD -> 0x01
WT -> 0x02
   ...
AB -> 0x10
   ...
ZZ -> 0xff

so that the original string is packed into 4 bytes without any loss of information:

IO123456 -> 0x49 0x4f 0x31 0x32 0x33 0x34 0x35 0x36
              \    /     \   /     \   /     \   /
               0x00       0x12      0x34      0x56

Of course this process can also be reversed to get the original ID string.

If the first two characters are not constant (but are always letters) and the remaining six characters are always numbers, a string "IO123456" can be packed into 5 bytes:

IO123456 -> 0x49 0x4f 0x31 0x32 0x33 0x34 0x35 0x36
             |    |      \   /     \   /     \   /
            0x49 0x4f     0x12      0x34      0x56

If there is a limited set of possible identifiers (the first two letters), you can encode these into a number and send that instead (as long as there no more than 256 combinations), e.g.:

IO -> 0x00
RD -> 0x01
WT -> 0x02
   ...
AB -> 0x10
   ...
ZZ -> 0xff

so that the original string is packed into 4 bytes without any loss of information:

IO123456 -> 0x49 0x4f 0x31 0x32 0x33 0x34 0x35 0x36
              \    /     \   /     \   /     \   /
               0x00       0x12      0x34      0x56

Of course this process can also be reversed to get the original ID string.

If the first two characters are not constant (but are always letters) and the remaining six characters are always numbers, a string like "IO123456" can be packed into 5 bytes by converting the numbers into binary-coded decimal (BCD) format:

IO123456 -> 0x49 0x4f 0x31 0x32 0x33 0x34 0x35 0x36
             |    |      \   /     \   /     \   /
            0x49 0x4f     0x12      0x34      0x56

If there is a limited set of possible identifiers (the first two letters), you can encode these into a number and send that instead (as long as there no more than 256 combinations), e.g.:

IO -> 0x00
RD -> 0x01
WT -> 0x02
   ...
AB -> 0x10
   ...
ZZ -> 0xff

so that the original string is packed into 4 bytes without any loss of information:

IO123456 -> 0x49 0x4f 0x31 0x32 0x33 0x34 0x35 0x36
              \    /     \   /     \   /     \   /
               0x00       0x12      0x34      0x56

Of course this process can also be reversed to get the original ID string.

added 5 characters in body
Source Link
ProphetV
  • 711
  • 6
  • 9

If the first two characters are not constant (but are always letters) and the remaining six characters are always numbers, a string "IO123456" can be packed into 5 bytes:

IO123456 -> 0x49 0x4f 0x31 0x32 0x33 0x34 0x35 0x36
             |    |      \   /     \   /     \   /
            0x49 0x4f     0x12      0x34      0x56

If there is a limited set of possible identifiers (the first two letters), you can encode these into a number and send that instead (as long as there no more than 256 combinations), e.g.:

IO ->   00x00
RD ->   10x01
WT ->   20x02
   ...
AB ->  100x10
   ...
ZZ -> 2550xff

so that the original string is packed into 4 bytes without any loss of information:

IO123456 -> 0x49 0x4f 0x31 0x32 0x33 0x34 0x35 0x36
              \    /     \   /     \   /     \   /
               0x00       0x12      0x34      0x56

Of course this process can also be reversed to get the original ID string.

If the first two characters are not constant (but are always letters) and the remaining six characters are always numbers, a string "IO123456" can be packed into 5 bytes:

IO123456 -> 0x49 0x4f 0x31 0x32 0x33 0x34 0x35 0x36
             |    |      \   /     \   /     \   /
            0x49 0x4f     0x12      0x34      0x56

If there is a limited set of possible identifiers (the first two letters), you can encode these into a number and send that instead (as long as there no more than 256 combinations), e.g.:

IO ->   0
RD ->   1
WT ->   2
   ...
AB ->  10
   ...
ZZ -> 255

so that the original string is packed into 4 bytes without any loss of information:

IO123456 -> 0x49 0x4f 0x31 0x32 0x33 0x34 0x35 0x36
              \    /     \   /     \   /     \   /
               0x00       0x12      0x34      0x56

Of course this process can also be reversed to get the original ID string.

If the first two characters are not constant (but are always letters) and the remaining six characters are always numbers, a string "IO123456" can be packed into 5 bytes:

IO123456 -> 0x49 0x4f 0x31 0x32 0x33 0x34 0x35 0x36
             |    |      \   /     \   /     \   /
            0x49 0x4f     0x12      0x34      0x56

If there is a limited set of possible identifiers (the first two letters), you can encode these into a number and send that instead (as long as there no more than 256 combinations), e.g.:

IO -> 0x00
RD -> 0x01
WT -> 0x02
   ...
AB -> 0x10
   ...
ZZ -> 0xff

so that the original string is packed into 4 bytes without any loss of information:

IO123456 -> 0x49 0x4f 0x31 0x32 0x33 0x34 0x35 0x36
              \    /     \   /     \   /     \   /
               0x00       0x12      0x34      0x56

Of course this process can also be reversed to get the original ID string.

Source Link
ProphetV
  • 711
  • 6
  • 9
Loading