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

Hex values ???????

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    Hi , can anybody give me a little explanation on what things like : 0x0001,0x48,0xFF,...... mean? m0n0

    B 1 Reply Last reply
    0
    • L Lost User

      Hi , can anybody give me a little explanation on what things like : 0x0001,0x48,0xFF,...... mean? m0n0

      B Offline
      B Offline
      BadJerry
      wrote on last edited by
      #2

      This means you are in base 16 : it goes like this 1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,10,11,12,... so A actually means 10 0x10 means: 1 * 16 + 0 = 16 0xFF means: 15*16 + 15 = 255 ... The reason hexadecimal is used is because 16 is a power of 2, so it is extremely easy to transform hexadecimal numbers into binary (and computers kinda like binary) 0 = 0000 1 = 0001 2 = 0010 3 = 0011 4 = 0100 5 = 0101 6 = 0110 7 = 0111 8 = 1000 9 = 1001 A = 1010 B = 1011 C = 1100 D = 1101 E = 1110 F = 1111 Therefore let say the following number 0x9AD has got the following binary value 1001 1010 1100 I hope this helps, Jerome

      S 1 Reply Last reply
      0
      • B BadJerry

        This means you are in base 16 : it goes like this 1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,10,11,12,... so A actually means 10 0x10 means: 1 * 16 + 0 = 16 0xFF means: 15*16 + 15 = 255 ... The reason hexadecimal is used is because 16 is a power of 2, so it is extremely easy to transform hexadecimal numbers into binary (and computers kinda like binary) 0 = 0000 1 = 0001 2 = 0010 3 = 0011 4 = 0100 5 = 0101 6 = 0110 7 = 0111 8 = 1000 9 = 1001 A = 1010 B = 1011 C = 1100 D = 1101 E = 1110 F = 1111 Therefore let say the following number 0x9AD has got the following binary value 1001 1010 1100 I hope this helps, Jerome

        S Offline
        S Offline
        Static x
        wrote on last edited by
        #3

        Thanks Jerome for your attention. You know i have written several functions for Adding,Subtracting,Multiplying,.... huge numbers, my functions look like : CString ADD(CString s1,CString s2) CString SUB(CString s1,CString s2) ... CString TO_BINARY(CString s1) you see i have a function as shown above TO_BINARY , which means that it does smth like this (just example) CString g = ToBinary("13");//so g="1101" and this function is too slow when instead of "31" i enter number with 100 digits or more, Could you please give me any idea if i can use theses 0x000,... or smth similar to make my algorithm faster Regards m0n0

        B 1 Reply Last reply
        0
        • S Static x

          Thanks Jerome for your attention. You know i have written several functions for Adding,Subtracting,Multiplying,.... huge numbers, my functions look like : CString ADD(CString s1,CString s2) CString SUB(CString s1,CString s2) ... CString TO_BINARY(CString s1) you see i have a function as shown above TO_BINARY , which means that it does smth like this (just example) CString g = ToBinary("13");//so g="1101" and this function is too slow when instead of "31" i enter number with 100 digits or more, Could you please give me any idea if i can use theses 0x000,... or smth similar to make my algorithm faster Regards m0n0

          B Offline
          B Offline
          BadJerry
          wrote on last edited by
          #4

          The simplest algorithm I can think of - and it does not mean it is the most efficient - is the following Is the number odd, insert a "1" at the beginning of the string, a "0" otherwise Divide the number by two (integer divide) (or you can substract 1 or 0 before you do the divide so you do not have to bother with floats) If the result is 0, exit else start again The division by two is usually very efficient on binary numbers (operator >> ) but if your numbers are stored as strings it is irrelevant. Let me know! Good luck!

          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