hex values to words
-
hey guys... im sure someone here will be able to help me with this one. Im looking at a log file that contains hex values I have a hex string that contains a date and time 0xd4, 0x16, 0x12, 0xbe The date is Word1 and the time is word2: The date is contained in 0xd4, 0x16 The time is contained in 0x12, 0xbe I know that each one of these 0x hex vlaues is a byte. I know that a word is two bytes Now here is where i am stuck because i dont know how to amalgamate the two bytes together. Should i be adding them togther or should i be using the MAKELONG API which puts 1 byte as the high word and the second as the lowword??
-
hey guys... im sure someone here will be able to help me with this one. Im looking at a log file that contains hex values I have a hex string that contains a date and time 0xd4, 0x16, 0x12, 0xbe The date is Word1 and the time is word2: The date is contained in 0xd4, 0x16 The time is contained in 0x12, 0xbe I know that each one of these 0x hex vlaues is a byte. I know that a word is two bytes Now here is where i am stuck because i dont know how to amalgamate the two bytes together. Should i be adding them togther or should i be using the MAKELONG API which puts 1 byte as the high word and the second as the lowword??
MAKELONG won't do it, a LONG is too big. 0xd4 << 8 + 0x16 will do it, in the first instance. You need to shift one value by 8 bits, so it sits above the other one.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
-
MAKELONG won't do it, a LONG is too big. 0xd4 << 8 + 0x16 will do it, in the first instance. You need to shift one value by 8 bits, so it sits above the other one.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
ahhh.. i see what your saying.. so 0xd4 = 11010100 and 0x16 = 00010110. by shifting 0xd4 8 places it becomes 1101010000000000 which leaves room to add the 0x16 to become 1101010000010110 (54294 dec) Thats excellent.. Thanks mate. is this the normal way i should be amalgamting hex values then?
-
MAKELONG won't do it, a LONG is too big. 0xd4 << 8 + 0x16 will do it, in the first instance. You need to shift one value by 8 bits, so it sits above the other one.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog
hey Christian, i seem to be tripping up over myself here. so that works for the date part.. I did the same with the time part. So: 0xd4 <<8 + 0x16 = 54294 (date) 0x12 <<8 + 0xbe = 4798 (time) now do i add these two results to equal 59092 or do i need to do: 54294 << 16 + 4798. Doing this though me a massive value: 3558211584
-
hey Christian, i seem to be tripping up over myself here. so that works for the date part.. I did the same with the time part. So: 0xd4 <<8 + 0x16 = 54294 (date) 0x12 <<8 + 0xbe = 4798 (time) now do i add these two results to equal 59092 or do i need to do: 54294 << 16 + 4798. Doing this though me a massive value: 3558211584
What date does 54294 represent, and what time does 4798 represent?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
What date does 54294 represent, and what time does 4798 represent?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
Sorry i was getting myself in a twist. the full 4 bytes represent the date AND time which means that i need to amalgamate the full 4 bytes into a DWORD. (which is 4 bytes or 2 words) 0xd4 <<8 + 0x16 = 54294 (date) 0x12 <<8 + 0xbe = 4798 (time) so the datetime value is actually: 54294 << 16 + 4798. 3558211584 which i believe to be seconds since the year 1996. - However i am having trouble converting this value to an actual time now! - i am trying to get it into a SYSTEMTIME struct.
-
Sorry i was getting myself in a twist. the full 4 bytes represent the date AND time which means that i need to amalgamate the full 4 bytes into a DWORD. (which is 4 bytes or 2 words) 0xd4 <<8 + 0x16 = 54294 (date) 0x12 <<8 + 0xbe = 4798 (time) so the datetime value is actually: 54294 << 16 + 4798. 3558211584 which i believe to be seconds since the year 1996. - However i am having trouble converting this value to an actual time now! - i am trying to get it into a SYSTEMTIME struct.
flippydeflippydebop wrote:
which i believe to be seconds since the year 1996.
Since 1996 is not considered a special year by the computer, you'll need to add the appropriate number of seconds to that value so that it reflects date/time since, for example, 1-Jan-1970. That's roughly 820,454,400. Now you can use the date/time functions that handle values from 1-Jan-1970.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb