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. hex values to words

hex values to words

Scheduled Pinned Locked Moved C / C++ / MFC
helpjsontutorialquestion
7 Posts 3 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.
  • F Offline
    F Offline
    flippydeflippydebop
    wrote on last edited by
    #1

    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??

    C 1 Reply Last reply
    0
    • F flippydeflippydebop

      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??

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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

      F 2 Replies Last reply
      0
      • C Christian Graus

        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

        F Offline
        F Offline
        flippydeflippydebop
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        • C Christian Graus

          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

          F Offline
          F Offline
          flippydeflippydebop
          wrote on last edited by
          #4

          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

          D 1 Reply Last reply
          0
          • F flippydeflippydebop

            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

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            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

            F 1 Reply Last reply
            0
            • D David Crow

              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

              F Offline
              F Offline
              flippydeflippydebop
              wrote on last edited by
              #6

              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.

              D 1 Reply Last reply
              0
              • F flippydeflippydebop

                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.

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                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

                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