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 do i convert a unsigned char to int ?

how do i convert a unsigned char to int ?

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

    how do i convert a unsigned char to int ? -Thanks

    Nice things do nice works

    T M R 3 Replies Last reply
    0
    • S Sakthiu

      how do i convert a unsigned char to int ? -Thanks

      Nice things do nice works

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      unsigned char uc = 15;
      int i = uc;

      [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

      M 1 Reply Last reply
      0
      • S Sakthiu

        how do i convert a unsigned char to int ? -Thanks

        Nice things do nice works

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        unsigned char g = 42;
        int h = g;

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        1 Reply Last reply
        0
        • T toxcct

          unsigned char uc = 15;
          int i = uc;

          [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          whoa - that's creepy :) Would be scary if we used the same variable names and value.

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          T 1 Reply Last reply
          0
          • M Mark Salsbery

            whoa - that's creepy :) Would be scary if we used the same variable names and value.

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            T Offline
            T Offline
            toxcct
            wrote on last edited by
            #5

            wait, I have better code:

            unsigned char uc = 15;
            int i = (signed int)(unsigned int)(unsigned short)uc;

            [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

            M 1 Reply Last reply
            0
            • T toxcct

              wait, I have better code:

              unsigned char uc = 15;
              int i = (signed int)(unsigned int)(unsigned short)uc;

              [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              Extreme coercion....I like it!

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              1 Reply Last reply
              0
              • S Sakthiu

                how do i convert a unsigned char to int ? -Thanks

                Nice things do nice works

                R Offline
                R Offline
                Rajesh R Subramanian
                wrote on last edited by
                #7

                Unsigned data can only hold positive data, whereas signed data can hold both positive and negative data. In your case, the unsigned data is a char, and the signed one is an int and the conversion goes on smoothly. Converting an unsigned double to a signed int MAY be disastrous, depending on the value of the double. You Google for signed vs unsigned - these are the basics. :)

                Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]

                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