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. 0x8000??????

0x8000??????

Scheduled Pinned Locked Moved C / C++ / MFC
question
10 Posts 5 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.
  • W Offline
    W Offline
    wow9999
    wrote on last edited by
    #1

    Hi there SHORT nState = GetAsyncKeyState(VK_CONTROL); BOOL bDown = (nState & 0x8000); what does 0x8000 mean and where can i find the infomation? By the way, What does (nState & 0x8000) mean? Thanks

    R N 2 Replies Last reply
    0
    • W wow9999

      Hi there SHORT nState = GetAsyncKeyState(VK_CONTROL); BOOL bDown = (nState & 0x8000); what does 0x8000 mean and where can i find the infomation? By the way, What does (nState & 0x8000) mean? Thanks

      R Offline
      R Offline
      Ryan Binns
      wrote on last edited by
      #2

      0x8000 is a hexadecimal number equal to 32768 in decimal or 1000000000000000 in binary. The value returned by GetAsyncKeyState() has bit 15 set if the key is down. However, since the value is a 16-bit SIGNED integer, a more intuitive way would be to code it like this:

      SHORT nState = GetAsyncKeyState(VK_CONROL);
      BOOL bDown = (nState < 0);

      If the state is less than 0, the key is pressed, otherwise it is released. Hope this helps,

      Ryan

      "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

      S 1 Reply Last reply
      0
      • W wow9999

        Hi there SHORT nState = GetAsyncKeyState(VK_CONTROL); BOOL bDown = (nState & 0x8000); what does 0x8000 mean and where can i find the infomation? By the way, What does (nState & 0x8000) mean? Thanks

        N Offline
        N Offline
        n 0
        wrote on last edited by
        #3

        the & operator compares each bit of both operands returning 1 only if both are 1. (1 & 1) = 1 (1 & 0) = 0 (0 & 1) = 0 (0 & 0) = 0 (001101 & 101011) = 001001 this way you know weather a bit has been set or not.

        1 Reply Last reply
        0
        • R Ryan Binns

          0x8000 is a hexadecimal number equal to 32768 in decimal or 1000000000000000 in binary. The value returned by GetAsyncKeyState() has bit 15 set if the key is down. However, since the value is a 16-bit SIGNED integer, a more intuitive way would be to code it like this:

          SHORT nState = GetAsyncKeyState(VK_CONROL);
          BOOL bDown = (nState < 0);

          If the state is less than 0, the key is pressed, otherwise it is released. Hope this helps,

          Ryan

          "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

          S Offline
          S Offline
          Steve S
          wrote on last edited by
          #4

          Intuitive?? :-D The bitmask is better, since it doesn't rely on SHORT being typedef-ed to a signed quantity. I know it should be, but hey, I've still got code from Win3.1 that works, and one day when I have a 64 bit processor, I might port it... :laugh: Steve S

          R 1 Reply Last reply
          0
          • S Steve S

            Intuitive?? :-D The bitmask is better, since it doesn't rely on SHORT being typedef-ed to a signed quantity. I know it should be, but hey, I've still got code from Win3.1 that works, and one day when I have a 64 bit processor, I might port it... :laugh: Steve S

            R Offline
            R Offline
            Ryan Binns
            wrote on last edited by
            #5

            Ok, ok. So I find it more intuitive :rolleyes:

            Ryan

            "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

            S 1 Reply Last reply
            0
            • R Ryan Binns

              Ok, ok. So I find it more intuitive :rolleyes:

              Ryan

              "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

              S Offline
              S Offline
              Steve S
              wrote on last edited by
              #6

              and I for one, will defend your right to say so. In my day, of course, one would have done a shift operation (or was that a rotate left? Ah, that's why I've stopped writing assembly code:-O ) and tested the carry flag... :sigh: Steve S

              R 1 Reply Last reply
              0
              • S Steve S

                and I for one, will defend your right to say so. In my day, of course, one would have done a shift operation (or was that a rotate left? Ah, that's why I've stopped writing assembly code:-O ) and tested the carry flag... :sigh: Steve S

                R Offline
                R Offline
                Ryan Binns
                wrote on last edited by
                #7

                Steve S wrote: In my day, of course, one would have done a shift operation (or was that a rotate left? Either one would work, as long as you used a 16-bit shift ;) BTW, what do you mean your day?? I'm 23, and still write assembler :P

                Ryan

                "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

                T 1 Reply Last reply
                0
                • R Ryan Binns

                  Steve S wrote: In my day, of course, one would have done a shift operation (or was that a rotate left? Either one would work, as long as you used a 16-bit shift ;) BTW, what do you mean your day?? I'm 23, and still write assembler :P

                  Ryan

                  "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

                  T Offline
                  T Offline
                  Tim Smith
                  wrote on last edited by
                  #8

                  But you are young and think it is cool to do ASM. Back in OUR day we had to. ;) Tim Smith I'm going to patent thought. I have yet to see any prior art.

                  R 1 Reply Last reply
                  0
                  • T Tim Smith

                    But you are young and think it is cool to do ASM. Back in OUR day we had to. ;) Tim Smith I'm going to patent thought. I have yet to see any prior art.

                    R Offline
                    R Offline
                    Ryan Binns
                    wrote on last edited by
                    #9

                    Tim Smith wrote: you are young and think it is cool to do ASM. Wrong. I do VC++ mainly, but I also do a lot of embedded programming - not much choice there... ;)

                    Ryan

                    "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

                    S 1 Reply Last reply
                    0
                    • R Ryan Binns

                      Tim Smith wrote: you are young and think it is cool to do ASM. Wrong. I do VC++ mainly, but I also do a lot of embedded programming - not much choice there... ;)

                      Ryan

                      "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

                      S Offline
                      S Offline
                      Steve S
                      wrote on last edited by
                      #10

                      Ah. Embedded programming. Fitting lots of functionality into a small device (in terms of memory and sometimes processor speed). Imagine having to do that *all* the time, when 32Kb was expensive, and mass-storage meant paper-tape... Of course, it meant viruses were easier to spot - if your executable size went up more than a few bytes, it probably wouldn't run anymore;P Steve S

                      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