how to assign unsigned char in c++?
-
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
-
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
mathivanaan wrote:
but aa is not assign that value?
how do you know this?
-
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
-
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
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.
-
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
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.
-
mathivanaan wrote:
please urgent
Sorry for not understanding: Is it the question that is urgent or the answer, or maybe both? Could you elaborate?
:-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] -
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
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] -
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
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 -
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, MikeThanks Mike. i try it your solution.