Unix Timestamp to hex conversion ..

Discussion in 'C++' started by ssmile03@gmail.com, Nov 8, 2013.

  1. Guest

    I am getting UNIX Timestamp as "1383889129". The ONLINE string to hex conversion gives me "31 33 38 33 38 38 39 31 32 39" which is 10 bytes but I wish to have only 8 bytes.

    Can I be helped.
     
    , Nov 8, 2013
    #1
    1. Advertising

  2. Ian Collins Guest

    wrote:
    > I am getting UNIX Timestamp as "1383889129". The ONLINE string to hex
    > conversion gives me "31 33 38 33 38 38 39 31 32 39" which is 10 bytes
    > but I wish to have only 8 bytes.
    >
    > Can I be helped.


    If you ask a C++ question you probably can.

    --
    Ian Collins
     
    Ian Collins, Nov 8, 2013
    #2
    1. Advertising

  3. jacob navia Guest

    Le 08/11/2013 06:44, a écrit :
    > I am getting UNIX Timestamp as "1383889129". The ONLINE string to hex conversion gives me "31 33 38 33 38 38 39 31 32 39"


    which is 10 bytes but I wish to have only 8 bytes.
    >
    > Can I be helped.
    >

    You are convertinv twice
    1) Converting binary 1383889129 into a character string "1383889129".
    2) Then you convert THAT STRING AGAIN into hexadecimal.

    You should convert DIRECTLY 1383889129 into 0x527C78E9 which is 8 bytes.
     
    jacob navia, Nov 8, 2013
    #3
  4. On 08.11.2013 06:44, wrote:
    > I am getting UNIX Timestamp as "1383889129". The ONLINE string to hex
    > conversion gives me "31 33 38 33 38 38 39 31 32 39" which is 10 bytes
    > but I wish to have only 8 bytes.


    There are three main ways to express a `double` value as a string of hex
    digits:

    A) Express the value in decimal, express each character of that as two
    hex digits.

    B) Use the hexadecimal conversion of C99/C++11. Compiler support for the
    C++ level is still sketchy. But using e.g. printf, this expresses the
    value directly but not uniquely in the base 16 system.

    C) Cast the value to unsigned integer of sufficient number of bits,
    express that integer value in hex.

    The common convention, e.g. for Mathematica, seems to be (C), while you
    appear to have employed (A).

    Cheers & hth.,

    - Alf
     
    Alf P. Steinbach, Nov 8, 2013
    #4
  5. On 08.11.2013 10:18, Alf P. Steinbach wrote:
    > On 08.11.2013 06:44, wrote:
    >> I am getting UNIX Timestamp as "1383889129". The ONLINE string to hex
    >> conversion gives me "31 33 38 33 38 38 39 31 32 39" which is 10 bytes
    >> but I wish to have only 8 bytes.

    >
    > There are three main ways to express a `double` value as a string of hex
    > digits:
    >
    > A) Express the value in decimal, express each character of that as two
    > hex digits.
    >
    > B) Use the hexadecimal conversion of C99/C++11. Compiler support for the
    > C++ level is still sketchy. But using e.g. printf, this expresses the
    > value directly but not uniquely in the base 16 system.
    >
    > C) Cast the value to unsigned integer of sufficient number of bits,
    > express that integer value in hex.
    >
    > The common convention, e.g. for Mathematica, seems to be (C), while you
    > appear to have employed (A).


    By "cast" I meant reinterpreting the bits of the value. This can be done
    by a `reinterpret_cast` of a pointer or reference to the value, or e.g.
    by `memcpy`. A good choice for destination type is array of unsigned `char`.


    Cheers & hth.,

    - Alf
     
    Alf P. Steinbach, Nov 8, 2013
    #5
  6. On 11/8/2013 12:44 AM, wrote:
    > I am getting UNIX Timestamp as "1383889129". The ONLINE string to hex conversion gives me "31 33 38 33 38 38 39 31 32 39" which is 10 bytes but I wish to have only 8 bytes.
    >
    > Can I be helped.
    >


    I took your number, guessed that it was decimal, started Calculator,
    pasted the number into the 'Programmer' view while 'Dec' was selected,
    then selected 'Hex' and got 527C78E9, which I then copied and pasted
    here. How hard that?

    V
    --
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Nov 8, 2013
    #6
  7. On Fri, 08 Nov 2013 09:33:36 +0100, jacob navia <>
    wrote:

    >Le 08/11/2013 06:44, a écrit :
    >> I am getting UNIX Timestamp as "1383889129". The ONLINE string to hex conversion gives me "31 33 38 33 38 38 39 31 32 39"

    >
    >which is 10 bytes but I wish to have only 8 bytes.
    >>
    >> Can I be helped.
    >>

    >You are convertinv twice
    >1) Converting binary 1383889129 into a character string "1383889129".
    >2) Then you convert THAT STRING AGAIN into hexadecimal.
    >
    >You should convert DIRECTLY 1383889129 into 0x527C78E9 which is 8 bytes.


    It is eight hex digits but it is only four 8-bit bytes.

    --
    Remove del for email
     
    Barry Schwarz, Nov 8, 2013
    #7
  8. In article <>,
    <> wrote:
    >I am getting UNIX Timestamp as "1383889129". The ONLINE string to hex
    >conversion gives me "31 33 38 33 38 38 39 31 32 39" which is 10 bytes
    >but I wish to have only 8 bytes.


    std::cout << std::hex << time(NULL) << std::endl;

    Mike.
     
    Miquel van Smoorenburg, Nov 9, 2013
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shahid Juma

    Unix Timestamp

    Shahid Juma, Jul 5, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    501
    Shahid Juma
    Jul 5, 2005
  2. Replies:
    10
    Views:
    6,229
    Neredbojias
    Aug 19, 2005
  3. Bengt Richter
    Replies:
    6
    Views:
    474
    Juha Autero
    Aug 19, 2003
  4. John Reese

    UNIX timestamp from a datetime class

    John Reese, Dec 6, 2005, in forum: Python
    Replies:
    2
    Views:
    18,428
    Tim Peters
    Dec 6, 2005
  5. Fibre Optic
    Replies:
    1
    Views:
    679
    =?iso-8859-1?q?Erik_Wikstr=F6m?=
    Feb 23, 2007
Loading...

Share This Page