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#
  4. hexadecimal numbers in C#

hexadecimal numbers in C#

Scheduled Pinned Locked Moved C#
questioncsharpc++tutorial
6 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.
  • R Offline
    R Offline
    Ranger49
    wrote on last edited by
    #1

    In C++ you can assing a variable a value of for instance 0xAAAA; I tried this in C# but it didn't work. What is the syntax like in C# when assigning a hexadecimal number? I couldn't find an example of this in books about C# which I checked, but I am sure people here know the answer to my question. Thanks! Ranger.

    D G 2 Replies Last reply
    0
    • R Ranger49

      In C++ you can assing a variable a value of for instance 0xAAAA; I tried this in C# but it didn't work. What is the syntax like in C# when assigning a hexadecimal number? I couldn't find an example of this in books about C# which I checked, but I am sure people here know the answer to my question. Thanks! Ranger.

      G Offline
      G Offline
      Giorgi Dalakishvili
      wrote on last edited by
      #2

      It works in c# too. ShellAPI constants[^]

      Giorgi Dalakishvili #region signature my articles #endregion

      1 Reply Last reply
      0
      • R Ranger49

        In C++ you can assing a variable a value of for instance 0xAAAA; I tried this in C# but it didn't work. What is the syntax like in C# when assigning a hexadecimal number? I couldn't find an example of this in books about C# which I checked, but I am sure people here know the answer to my question. Thanks! Ranger.

        D Offline
        D Offline
        DaveyM69
        wrote on last edited by
        #3

        int x = 0xAAAA;

        Dave

        R 1 Reply Last reply
        0
        • D DaveyM69

          int x = 0xAAAA;

          Dave

          R Offline
          R Offline
          Ranger49
          wrote on last edited by
          #4

          DaveyM69 wrote:

          int x = 0xAAAA;

          Thanks, I wondered... I think my error message was caused by the fact that I didn't know how many 'A's fit into a short type number. Ranger

          L K 2 Replies Last reply
          0
          • R Ranger49

            DaveyM69 wrote:

            int x = 0xAAAA;

            Thanks, I wondered... I think my error message was caused by the fact that I didn't know how many 'A's fit into a short type number. Ranger

            L Offline
            L Offline
            leppie
            wrote on last edited by
            #5

            Ranger49 wrote:

            I think my error message was caused by the fact that I didn't know how many 'A's fit into a short type number.

            Guess you know now ;P short = 2 bytes int = 4 bytes long = 8 bytes

            xacc.ide - now with TabsToSpaces support
            IronScheme - 1.0 alpha 4a out now (29 May 2008)

            1 Reply Last reply
            0
            • R Ranger49

              DaveyM69 wrote:

              int x = 0xAAAA;

              Thanks, I wondered... I think my error message was caused by the fact that I didn't know how many 'A's fit into a short type number. Ranger

              K Offline
              K Offline
              Kythen
              wrote on last edited by
              #6

              Ranger49 wrote:

              I think my error message was caused by the fact that I didn't know how many 'A's fit into a short type number.

              Don't forget to pay attention to whether that short number is signed or unsigned!

              short a = 0x7AAA; // OK!
              short b = 0xAAAA; // Doh! Won't work!
              ushort c = 0xAAAA; // OK!

              You can also use the 'unchecked' syntax to force it to be a signed short.

              short x = unchecked((short)0xAAAA); // Also OK!

              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