Unix Timestamp to hex conversion ..

S

ssmile03

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

Ian Collins

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

jacob navia

Le 08/11/2013 06:44, (e-mail address removed) 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.
 
A

Alf P. Steinbach

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
 
A

Alf P. Steinbach

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
 
V

Victor Bazarov

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
 
B

Barry Schwarz

Le 08/11/2013 06:44, (e-mail address removed) a écrit :

which is 10 bytes but I wish to have only 8 bytes.
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.
 
M

Miquel van Smoorenburg

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top