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. .NET (Core and Framework)
  4. Converting from base10 to base16 and save it in unsigned char array?

Converting from base10 to base16 and save it in unsigned char array?

Scheduled Pinned Locked Moved .NET (Core and Framework)
data-structureshelptutorialquestion
4 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.
  • K Offline
    K Offline
    Kiran Satish
    wrote on last edited by
    #1

    Hello, I would like to convert a decimal number (base10) into hexadecimal and then save it into an unsigned char array. I have an integer whose value increments from 1024 to a max of 2047 in steps of 1 whenever the user clicks a button. At each step I need to convert it to a hexadecimal number and save it into an unsigned char array or 2 elements so that I can send it to a device via USB. For example: If I want to send 1955 decimal number I would like to have my unsigned char array as below Out[0] = 0x07; out[1] = 0xA3 then I can use my transferdata(out) function. Can someone help me with this? thanks in advance

    PKNT

    L 1 Reply Last reply
    0
    • K Kiran Satish

      Hello, I would like to convert a decimal number (base10) into hexadecimal and then save it into an unsigned char array. I have an integer whose value increments from 1024 to a max of 2047 in steps of 1 whenever the user clicks a button. At each step I need to convert it to a hexadecimal number and save it into an unsigned char array or 2 elements so that I can send it to a device via USB. For example: If I want to send 1955 decimal number I would like to have my unsigned char array as below Out[0] = 0x07; out[1] = 0xA3 then I can use my transferdata(out) function. Can someone help me with this? thanks in advance

      PKNT

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Something like ...

      Out[0] = decimalNumber / 256;
      Out[1] = decimalNumber % 256;

      One of these days I'm going to think of a really clever signature.

      K 1 Reply Last reply
      0
      • L Lost User

        Something like ...

        Out[0] = decimalNumber / 256;
        Out[1] = decimalNumber % 256;

        One of these days I'm going to think of a really clever signature.

        K Offline
        K Offline
        Kiran Satish
        wrote on last edited by
        #3

        Thanks for your reply, it works perfect. Looks very simple, wonder why I didnt get that idea (I did many times before in similar ways). These days I have to start thinking from scratch. :)

        PKNT

        L 1 Reply Last reply
        0
        • K Kiran Satish

          Thanks for your reply, it works perfect. Looks very simple, wonder why I didnt get that idea (I did many times before in similar ways). These days I have to start thinking from scratch. :)

          PKNT

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Kiran Satish wrote:

          These days I have to start thinking from scratch.

          Yeah, me too.

          One of these days I'm going to think of a really clever signature.

          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