Convert To (48 bits, Little Endian)

LKHaSSeR 21 Reputation points
2021-02-15T10:37:21.803+00:00

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:

Fsc5K.jpg

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 ...

7BdKN.jpg

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

lIPAM.jpg

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,524 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 114K Reputation points
    2021-02-15T11:14:16.327+00:00

    Converting 38, 1, 33 to hexadecimal, you will get 26, 1, 21, which looks like a 26/01/2021 date. To make a date, try something like this:

    byte[] all_bytes = . . .
    
    DateTime date = new DateTime( 
        2000 + int.Parse( Convert.ToString( all_bytes[5], 16 ) ),
        int.Parse( Convert.ToString( all_bytes[4], 16 ) ),
        int.Parse( Convert.ToString( all_bytes[3], 16 ) ) );
    

    To extract the serial number as an array of bytes:

    byte[] sn = all_bytes.Skip( 3 ).Take( 6 ).ToArray( );
    

    Then you can also show it as string in various forms.


1 additional answer

Sort by: Most helpful
  1. Ken Tucker 5,846 Reputation points
    2021-02-15T11:11:56.49+00:00

    Try something like this. dateRecieved is the bytes you received via UDP

            var data = System.Text.Encoding.Unicode.GetString(dataReceived);
    
    0 comments No comments