Code to reverse a HEX value and convert to Decimal


hi all,

i using pn532 rfid reader module.

in example library mifare uid reading sketch.

it outputs reverse hex value on serial monitor so; 0xce 0x67 0x6e 0x5a

so, correct uid need reverse value (5a6e67ce) , have been using online converters etc value want (1517184974)

ideally serial monitor spit out value rather reverse code, know (i'm sure) can done in code unfortunately don't have ability (i'm bad @ maths), hoping come rescue...

i don't think modification complicated if know doing, although i'm not qualified make assertion.

thank reading , advice may have offer...

here original code reference;

code: [select]
/**************************************************************************/
/*!
    example attempt connect iso14443a
    card or tag , retrieve basic information it
    can used determine type of card is.   
   
    note need baud rate 115200 because need print
    out data , read card @ same time!

   
*/
/**************************************************************************/

// choose spi or i2c or hsu
#if 0
  #include <spi.h>
  #include <pn532_spi.h>
  #include "pn532.h"

  pn532_spi pn532spi(spi, 10);
  pn532 nfc(pn532spi);
#elif 0
  #include <pn532_hsu.h>
  #include <pn532.h>
     
  pn532_hsu pn532hsu(serial1);
  pn532 nfc(pn532hsu);
#else
  #include <wire.h>
  #include <pn532_i2c.h>
  #include <pn532.h>

  pn532_i2c pn532i2c(wire);
  pn532 nfc(pn532i2c);
#endif

void setup(void) {
  serial.begin(115200);
  serial.println("hello!");

  nfc.begin();

  uint32_t versiondata = nfc.getfirmwareversion();
  if (! versiondata) {
    serial.print("didn't find pn53x board");
    while (1); // halt
  }
 
  // got ok data, print out!
  serial.print("found chip pn5"); serial.println((versiondata>>24) & 0xff, hex);
  serial.print("firmware ver. "); serial.print((versiondata>>16) & 0xff, dec);
  serial.print('.'); serial.println((versiondata>>8) & 0xff, dec);
 
  // set max number of retry attempts read card
  // prevents waiting forever card, is
  // default behaviour of pn532.
  nfc.setpassiveactivationretries(0xff);
 
  // configure board read rfid tags
  nfc.samconfig();
   
  serial.println("waiting iso14443a card");
}

void loop(void) {
  boolean success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // buffer store returned uid
  uint8_t uidlength;                        // length of uid (4 or 7 bytes depending on iso14443a card type)
 
  // wait iso14443a type cards (mifare, etc.).  when 1 found
  // 'uid' populated uid, , uidlength indicate
  // if uid 4 bytes (mifare classic) or 7 bytes (mifare ultralight)
  success = nfc.readpassivetargetid(pn532_mifare_iso14443a, &uid[0], &uidlength);
 
  if (success) {
    serial.println("found card!");
    serial.print("uid length: ");serial.print(uidlength, dec);serial.println(" bytes");
    serial.print("uid value: ");
    (uint8_t i=0; < uidlength; i++)
    {
      serial.print(" 0x");serial.print(uid[i], hex);
    }
    serial.println("");
    // wait 1 second before continuing
    delay(1000);
  }
  else
  {
    // pn532 timed out waiting card
    serial.println("timed out waiting card");
  }
}

quote
it outputs reverse hex value on serial monitor so; 0xce 0x67 0x6e 0x5a

what? why think bytes output in reverse order?

quote
ideally serial monitor spit out value rather reverse code, know (i'm sure) can done in code unfortunately don't have ability (i'm bad @ maths), hoping come rescue...

how @ math have to output data in order 3, 2, 1, 0 instead of 0, 1, 2, 3? it's 1 line of code change. here's hint: it's loop needs changing.



Arduino Forum > Using Arduino > Programming Questions > Code to reverse a HEX value and convert to Decimal


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support