Converting Timestamp into hex of 8 bytes

Sorry for wrong post. I have a string Timestamp of 1383889129 which on ONLINE conversion from string to hex gives a 10 bytes as "31 33 38 33 38 38 39 31 32 39". But, the need is to have the TIMEStamp in 8 bytes only. OR any other way using either C++ or Boost where I can convert the string Timestamp of 1383889129 into 8 bytes hex value. Any clue ..!!

I have a string Timestamp of 1383889129 which on ONLINE conversion from string to hex gives a 10 bytes as "31 33 38 33 38 38 39 31 32 39".
The above is not "conversion from string to hex", but merely a hex representation of every ascii character in "1383889129" string.
But, the need is to have the TIMEStamp in 8 bytes only.
It's unclear what you want exactly. If you need a time-stamp as a number, use boost::lexical_cast<int>("1383889129") or any other ascii-to-int conversion.

YES, do have the TIMESTAMP from string viz 1383889129. Since, the declaration of TIMESTAMP is "char TIMESTAMP[8]", so looking how to convert this? On Fri, Nov 8, 2013 at 11:49 AM, Igor R <boost.lists@gmail.com> wrote:
I have a string Timestamp of 1383889129 which on ONLINE conversion from string to hex gives a 10 bytes as "31 33 38 33 38 38 39 31 32 39".
The above is not "conversion from string to hex", but merely a hex representation of every ascii character in "1383889129" string.
But, the need is to have the TIMEStamp in 8 bytes only.
It's unclear what you want exactly. If you need a time-stamp as a number, use boost::lexical_cast<int>("1383889129") or any other ascii-to-int conversion. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

How you can store 10 digits to 8 chars? Probably you mean "char TIMESTAMP[10]" or "char TIMESTAMP[11]" (because you need a null-terminated symbol for c-strings). So if you have not a c-string, but just array with digit's symbols - I suggest you to write simple convert function like this int number = 0; for (int i = 0; i < num_of_digits; ++i) { number = number*10 + TIMESTAMP[i]; } In case with c-strings use Igor R solution. On Fri, Nov 8, 2013 at 7:54 PM, Rahul Mathur <srivmuk@gmail.com> wrote:
YES, do have the TIMESTAMP from string viz 1383889129. Since, the declaration of TIMESTAMP is "char TIMESTAMP[8]", so looking how to convert this?
On Fri, Nov 8, 2013 at 11:49 AM, Igor R <boost.lists@gmail.com> wrote:
I have a string Timestamp of 1383889129 which on ONLINE conversion from string to hex gives a 10 bytes as "31 33 38 33 38 38 39 31 32 39".
The above is not "conversion from string to hex", but merely a hex representation of every ascii character in "1383889129" string.
But, the need is to have the TIMEStamp in 8 bytes only.
It's unclear what you want exactly. If you need a time-stamp as a number, use boost::lexical_cast<int>("1383889129") or any other ascii-to-int conversion. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

2013/11/8 Rahul Mathur <srivmuk@gmail.com>
On Fri, Nov 8, 2013 at 11:49 AM, Igor R <boost.lists@gmail.com> wrote:
I have a string Timestamp of 1383889129 which on ONLINE conversion from string to hex gives a 10 bytes as "31 33 38 33 38 38 39 31 32 39".
The above is not "conversion from string to hex", but merely a hex representation of every ascii character in "1383889129" string.
But, the need is to have the TIMEStamp in 8 bytes only.
It's unclear what you want exactly. If you need a time-stamp as a number, use boost::lexical_cast<int>("1383889129") or any other ascii-to-int conversion.
YES, do have the TIMESTAMP from string viz 1383889129. Since, the
declaration of TIMESTAMP is "char TIMESTAMP[8]", so looking how to convert this? I think you didn't provide enough information, so different solutions can give different answers. Perhaps you don't have enough information or it's up to you to choose? 1383889129 looks like a decimal it. You say you get it as a string. You can convert it to a 32-bit int like this: string s = "1383889129"; uint32_t i = boost::lexical_cast<uint32_t>(s); // you probably can use plain old unsigned int if it has 32 bits Now you can put this int's hex representation into an array of 8 bytes. I assume each byte is supposed to contain a character representing a hexadecimal digit [0-9a-f]. Here it is left unspecified, if ts[0] should be the least or most significant digit. Here's what you can do (ts[0] will be the most significant digit; warning: not tested, I'm not sure if I named the manipulators right, but I hope you'll get the idea): TIMESTAMP ts; ostringstream os; os << hex << setfill('0') << setw(8) << i; boost::copy( os.str(), ts ); // copy from Boost.Range HTH, Kris
participants (4)
-
Igor R
-
Krzysztof Czainski
-
Kulti
-
Rahul Mathur