Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Help with ASCII conversion

Help with ASCII conversion

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialdata-structureshelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rexpiper
    wrote on last edited by
    #1

    I have a date time stamp which I have read from a file. I have read it as ascii characters and have stored it in a character array as follows: The data is stored in the reverse order in the file where I read it i.e. [0] [1] [2] [3] [4] [5] [6] [7] has to be reordered as [7] [6] [5] [4] [2] [1] [0]. The bytes are put into a character array as a hexadecimal representation of a timestamp. (actual example) dt = "0x01c5556a92792c8c0" Now in order to pass it to the localtime function I need to convert this ascii hex representation of my timestamp to an int64. I must be having a senior moment but I can't figure out how to do this (seemingly simple) operation. Could someone more experienced please help me with this? Thanks

    K 1 Reply Last reply
    0
    • R rexpiper

      I have a date time stamp which I have read from a file. I have read it as ascii characters and have stored it in a character array as follows: The data is stored in the reverse order in the file where I read it i.e. [0] [1] [2] [3] [4] [5] [6] [7] has to be reordered as [7] [6] [5] [4] [2] [1] [0]. The bytes are put into a character array as a hexadecimal representation of a timestamp. (actual example) dt = "0x01c5556a92792c8c0" Now in order to pass it to the localtime function I need to convert this ascii hex representation of my timestamp to an int64. I must be having a senior moment but I can't figure out how to do this (seemingly simple) operation. Could someone more experienced please help me with this? Thanks

      K Offline
      K Offline
      Kuniva
      wrote on last edited by
      #2

      Maybe not the shortest way, but should work:

      __int64 test;
      char buf[128];
      const char dt[] = "0x01c5556a92792c8c";

      memset(buf, 0, sizeof(buf));

      for(int i=0;i<8;i++)
      {
      int n = strlen(dt) - ((i+1)*2);
      sprintf(&buf[i*2], "%c%c", dt[n], dt[n+1]);
      }

      sscanf(buf, "%16I64x", &test);

      Kuniva --------------------------------------------

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups