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 assign unsigned char in c++?

how to assign unsigned char in c++?

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
9 Posts 7 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.
  • M Offline
    M Offline
    mathivanaan
    wrote on last edited by
    #1

    Hi, I am working Fodero eclipse c++. I have one unsigned char(one byte unsigned integer) variable. i am passing some integer value. like unsigned char aa= 10; but aa is not assign that value? How to pass that value on unsigned char. same like i am using unsigned long, i add 'u' on the end the passing number. unsigned long bb= 10u; here i got bb value is 10. how to get unsigned char value?. Any ideas or link share to me. please urgent Regards, M.Mathivanan

    C N S L CPalliniC 6 Replies Last reply
    0
    • M mathivanaan

      Hi, I am working Fodero eclipse c++. I have one unsigned char(one byte unsigned integer) variable. i am passing some integer value. like unsigned char aa= 10; but aa is not assign that value? How to pass that value on unsigned char. same like i am using unsigned long, i add 'u' on the end the passing number. unsigned long bb= 10u; here i got bb value is 10. how to get unsigned char value?. Any ideas or link share to me. please urgent Regards, M.Mathivanan

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      mathivanaan wrote:

      but aa is not assign that value?

      how do you know this?

      image processing toolkits | batch image processing

      1 Reply Last reply
      0
      • M mathivanaan

        Hi, I am working Fodero eclipse c++. I have one unsigned char(one byte unsigned integer) variable. i am passing some integer value. like unsigned char aa= 10; but aa is not assign that value? How to pass that value on unsigned char. same like i am using unsigned long, i add 'u' on the end the passing number. unsigned long bb= 10u; here i got bb value is 10. how to get unsigned char value?. Any ideas or link share to me. please urgent Regards, M.Mathivanan

        N Offline
        N Offline
        Niklas L
        wrote on last edited by
        #3

        mathivanaan wrote:

        please urgent

        Sorry for not understanding: Is it the question that is urgent or the answer, or maybe both? Could you elaborate?

        home

        CPalliniC 1 Reply Last reply
        0
        • M mathivanaan

          Hi, I am working Fodero eclipse c++. I have one unsigned char(one byte unsigned integer) variable. i am passing some integer value. like unsigned char aa= 10; but aa is not assign that value? How to pass that value on unsigned char. same like i am using unsigned long, i add 'u' on the end the passing number. unsigned long bb= 10u; here i got bb value is 10. how to get unsigned char value?. Any ideas or link share to me. please urgent Regards, M.Mathivanan

          S Offline
          S Offline
          Stefan_Lang
          wrote on last edited by
          #4

          Your assignment looks valid. How did you test that aa does not hold the correct value? If you checked in the debugger, or pass it to cout, please remember that the type is still a character, and the standard representation is as a character. The value 10 is a non-prinitable character, and as such would show no visible output either in the debugger or in a printout, unless you convert aa to int first.

          1 Reply Last reply
          0
          • M mathivanaan

            Hi, I am working Fodero eclipse c++. I have one unsigned char(one byte unsigned integer) variable. i am passing some integer value. like unsigned char aa= 10; but aa is not assign that value? How to pass that value on unsigned char. same like i am using unsigned long, i add 'u' on the end the passing number. unsigned long bb= 10u; here i got bb value is 10. how to get unsigned char value?. Any ideas or link share to me. please urgent Regards, M.Mathivanan

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            unsigned char aa = (unsigned char)10;

            BTW: when you get build-time messages or run-time errors/exceptions, you should mention them verbatim in your question. :)

            Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

            1 Reply Last reply
            0
            • N Niklas L

              mathivanaan wrote:

              please urgent

              Sorry for not understanding: Is it the question that is urgent or the answer, or maybe both? Could you elaborate?

              home

              CPalliniC Offline
              CPalliniC Offline
              CPallini
              wrote on last edited by
              #6

              :-D

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              In testa che avete, signor di Ceprano?

              1 Reply Last reply
              0
              • M mathivanaan

                Hi, I am working Fodero eclipse c++. I have one unsigned char(one byte unsigned integer) variable. i am passing some integer value. like unsigned char aa= 10; but aa is not assign that value? How to pass that value on unsigned char. same like i am using unsigned long, i add 'u' on the end the passing number. unsigned long bb= 10u; here i got bb value is 10. how to get unsigned char value?. Any ideas or link share to me. please urgent Regards, M.Mathivanan

                CPalliniC Offline
                CPalliniC Offline
                CPallini
                wrote on last edited by
                #7

                mathivanaan wrote:

                unsigned char aa= 10;

                The statement is indeed correct. Probably the fault is in the way you check it. :)

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                [My articles]

                In testa che avete, signor di Ceprano?

                1 Reply Last reply
                0
                • M mathivanaan

                  Hi, I am working Fodero eclipse c++. I have one unsigned char(one byte unsigned integer) variable. i am passing some integer value. like unsigned char aa= 10; but aa is not assign that value? How to pass that value on unsigned char. same like i am using unsigned long, i add 'u' on the end the passing number. unsigned long bb= 10u; here i got bb value is 10. how to get unsigned char value?. Any ideas or link share to me. please urgent Regards, M.Mathivanan

                  M Offline
                  M Offline
                  mike codeproject
                  wrote on last edited by
                  #8

                  You are getting a 10 as a binary value with that assignment. If you use cout<< to print it out, however, you won't see a 10. That's because cout<< called on a char or unsigned char value always treats the value as a character, not a number. What you will see is that the next thing you output will begin on a new line. The 10 translates to a '\n' newline character. To see the binary value of a char as a unsigned decimal value, use a typecast first.

                  unsigned char bb = 10;
                  cout << "** bb looks like [" << bb <<] this." << endl;
                  cout << "** (unsigned)bb looks like: " << (unsigned)bb << endl;

                  this. ** (unsigned)bb looks like: 10 I put the unsigned char version in [] brackets so you can see what the effect is on the output. Cheers, Mike

                  M 1 Reply Last reply
                  0
                  • M mike codeproject

                    You are getting a 10 as a binary value with that assignment. If you use cout<< to print it out, however, you won't see a 10. That's because cout<< called on a char or unsigned char value always treats the value as a character, not a number. What you will see is that the next thing you output will begin on a new line. The 10 translates to a '\n' newline character. To see the binary value of a char as a unsigned decimal value, use a typecast first.

                    unsigned char bb = 10;
                    cout << "** bb looks like [" << bb <<] this." << endl;
                    cout << "** (unsigned)bb looks like: " << (unsigned)bb << endl;

                    this. ** (unsigned)bb looks like: 10 I put the unsigned char version in [] brackets so you can see what the effect is on the output. Cheers, Mike

                    M Offline
                    M Offline
                    mathivanaan
                    wrote on last edited by
                    #9

                    Thanks Mike. i try it your solution.

                    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