Why unsigned char is necessary? What is its use exactly?
Why unsigned char is necessary? What is its use exactly?
I do not know about necessary, but unsigned char can be useful when you want to work with a byte, especially with respect to bitwise operations. What motivated you to ask your questions?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
It is important when you don't want your program to store negative values.
Spidey out!
signed char, or char by default has a range of -128 to 127
unsigned char has a range of 0-255
if you need to work with numbers larger than 127 using only a single byte, you need unsigned char
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
NO still why unsigned.....and in case of signed why sign bit is necessary?
How about actually reading the replies?
...
Maybe because the computer needs it to determine if it means 255 or -1?
unsigned char also has no padding bits, so you can use it to copy all the bits of an object from one location to another. char, signed char, and all the other types except the optional fixed-width extended integer types might have padding, and might trap when used as the type to read another type's bytes.
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010
srand() fuction needs unsigned int as argument, at least was what I've read in my book :P