0

I am communicating with a card via UDP, sending messages and receiving responses with the data I want! I have a small problem in the conversion of these two parameters: Paremeters Argument

When I send the command 0x22 to read the firmware version I get this response (index 3,4,5) but they are not in yymmdd format given the results I got 38 and 33 ... 0x22 Reponse

When I send the command 0x21 to read the UI version i get this result, how i can convert it to 48 bit little endian 0x21 Réponse

  • `int serialNumber = byte1 + 256 * byte2 + (256*256 * byte3) + ... + (256*256*256*256*256 * byte6)` – xanatos Feb 15 '21 at 10:09
  • take a look at https://learn.microsoft.com/en-us/dotnet/api/system.net.ipaddress.networktohostorder?view=net-5.0 -- for standard Endianess conversion. – Prateek Shrivastava Feb 15 '21 at 10:10
  • Error Complitor L'opération engendre un dépassement de capacité au moment de la compilation dans le mode check @xanatos – QuatreHuit Feb 15 '21 at 10:31
  • @QuatreHuit Ah right... 48 bits... You need 64 bits... `long serialNumber = byte1 + 256L * byte2 + (256L*256L * byte3) + ... + (256L*256L*256L*256L*256L * byte6)`. Use a `long` and put a L after each 256, so that the operations are done in `long` – xanatos Feb 15 '21 at 10:37

1 Answers1

0

The easiest way is something like:

long serialNumber = byte1 + (256L * byte2) + (256L*256L * byte3) + ... + (256L*256L*256L*256L*256L * byte6)

Note that it is surely possible to do it with bit-shifting:

long serialNumber = ((long)byte1) | ((long)byte2 << 8) | ((long)byte3 << 16) | ... | ((long)byte6 << 40)

Both are based on how a little-endian number is represented in memory.

xanatos
  • 109,618
  • 12
  • 197
  • 280