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. How to redefine HEX symbols

How to redefine HEX symbols

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
6 Posts 2 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.
  • T Offline
    T Offline
    tbrake
    wrote on last edited by
    #1

    Hallo I'd like to change the chars printed unsing HEX. Sample: int nHex = 0xABCDEF; char nHexText[7]; sprintf(nHexText,"%x",nHex); // Result for example // nHexText = ":;<=>?"; // This is [hex value] + [48] ?!?! By now i convert as hex to string and use some macros for each char to convert. Is there any posibility to change the symbol by just using sprintf ?? THX Timen

    B 1 Reply Last reply
    0
    • T tbrake

      Hallo I'd like to change the chars printed unsing HEX. Sample: int nHex = 0xABCDEF; char nHexText[7]; sprintf(nHexText,"%x",nHex); // Result for example // nHexText = ":;<=>?"; // This is [hex value] + [48] ?!?! By now i convert as hex to string and use some macros for each char to convert. Is there any posibility to change the symbol by just using sprintf ?? THX Timen

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

      tbrake wrote:

      change the symbol

      I'm not sure what symbol is referring to.

      tbrake wrote:

      now i convert as hex to string

      On a side note, "hex" is not a number, it is a radix for representing the number value in some base or number system. You can view a number using any radix you desire. Whether you choose to look at it in base-2, 10, 16, 32 does not change the number. Anyway, if possible, please clarify your question.

      T 1 Reply Last reply
      0
      • B bob16972

        tbrake wrote:

        change the symbol

        I'm not sure what symbol is referring to.

        tbrake wrote:

        now i convert as hex to string

        On a side note, "hex" is not a number, it is a radix for representing the number value in some base or number system. You can view a number using any radix you desire. Whether you choose to look at it in base-2, 10, 16, 32 does not change the number. Anyway, if possible, please clarify your question.

        T Offline
        T Offline
        tbrake
        wrote on last edited by
        #3

        hallo OK radix ... will look up this just after this mail.. I mean Displaying Hex as String measn unsing the symbols 0 1 2 3 4 5 6 7 8 9 A B C D E F Now i need 0 1 2 3 4 5 6 7 8 9 : ; < = > ? I know this is strange but i have some old hardware - this is only able to understand these symbols no hex !!! X| and the second problem is i need a very fast calculation. THX

        B 2 Replies Last reply
        0
        • T tbrake

          hallo OK radix ... will look up this just after this mail.. I mean Displaying Hex as String measn unsing the symbols 0 1 2 3 4 5 6 7 8 9 A B C D E F Now i need 0 1 2 3 4 5 6 7 8 9 : ; < = > ? I know this is strange but i have some old hardware - this is only able to understand these symbols no hex !!! X| and the second problem is i need a very fast calculation. THX

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

          Wait a minute, one an earlier thread today you stated...

          tbrake wrote:

          Hallo 1. Well at least it makes sence. cause i have to controll some hardware. To calculate the needed commands the shortes way is to interprete int as Hex bit shift this and the result is the needed command.

          I apologize but this is making no sense. I would love to help but I've been burned by questions that didn't describe the problem correctly. I would spend my valuable time working out a solution to help out a fellow CP member only to find out later on that the problem context was different enough to warrant a totally different solution thus rendering my code snippets useless. Are you sure you need a character translation for the hex representation of a number?

          1 Reply Last reply
          0
          • T tbrake

            hallo OK radix ... will look up this just after this mail.. I mean Displaying Hex as String measn unsing the symbols 0 1 2 3 4 5 6 7 8 9 A B C D E F Now i need 0 1 2 3 4 5 6 7 8 9 : ; < = > ? I know this is strange but i have some old hardware - this is only able to understand these symbols no hex !!! X| and the second problem is i need a very fast calculation. THX

            B Offline
            B Offline
            bob16972
            wrote on last edited by
            #5

            does the solution require that you send the indivdual characters representing the number or sending the number itself?

            T 1 Reply Last reply
            0
            • B bob16972

              does the solution require that you send the indivdual characters representing the number or sending the number itself?

              T Offline
              T Offline
              tbrake
              wrote on last edited by
              #6

              I am not sure but i think i need the numeric interpretation. The controller is a GPIB card (16 BIT connector) - to the receiver there is an initialisation string send to as char "N00,TH0,V0123456789:;<=>?\n" changing anything here will end up in errors. ... ah i think i can do this like : int hex = 0x2ABCDEF; cmd[0] = ((hex & 0x0F000000)>>24)+48; cmd[1] = ((hex & 0x00F00000)>>20)+48; cmd[2] = ((hex & 0x000F0000)>>16)+48; cmd[3] = ((hex & 0x0000F000)>>12)+48; ... OK i try this :cool: THX Timen

              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