简体   繁体   中英

Decoding RFID data hexadecimal math issue C++

I currently am stuck at getting the needed outcome data from my RFID card. I got it decoded but now I need to do a few more things in order to get the final card number off the back of the card.

The cryptic value was E********B 0 E . Decrypting it turned into 0000003048D1263B .

Now I have 3 more steps to take in order to get to my wanted card number.

Step 1) Mask off the lower 20-bits (which should give me 0x1263B) I am unsure of how to go about doing that using C++.

Step 2) Divide by 2 to strip off the lower parity bit (which should be 0x931d). And again, I'm unsure of how to go about doing this in C++.

Step 3) Convert hexadecimal value to decimal value (which would equal my wanted card number). This should be easily done using C++ at this point - though hard to confirm that since I am on step 1).

const char* original = "0x931d";
unsigned long n = std::strtoul(original, nullptr, 16);

All of this looks to me like RegEX does to most people - complicated and not understanding why it does what it does but gives the correct output.

All help would be appreciated!

Step 1) Mask off the lower 20-bits (which should give me 0x1263B) I am unsure of how to go about doing that using C++.

First, create a binary value containing 1's for each bit you want to save or mask. In your case it would be 0b111 1111 1111 1111 1111, or 0xFFFFF And your value with the mask using the & operator.

  result = value & 0xFFFFF;  

Step 2) Divide by 2 to strip off the lower parity bit (which should be 0x931d). And again, I'm unsure of how to go about doing this in C++.

Dividing by 2 is the same as right shifting the value by 1 place.

result = result >> 1;  

Step 3) Convert hexadecimal value to decimal value (which would equal my wanted card number). This should be easily done using C++ at this point - though hard to confirm that since I am on step 1).

Is this necessary? Conversion is only for Users.

  cout << result;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM