Question

char takes values in the range of -128 to 127. By simply putting unsigned before char the range changes to 0-255. How to achieve the same effect in a string? So that all chars in that string take values from 0-255?

Was it helpful?

Solution

char takes values in the range of -128 to 127.

No.

char is implementation-defined, it could be either signed char or unsigned char depending on what your compiler chose to use. And char doesn't necessarily means byte BTW... (there are some platforms where a char is 16 bits for example)

If you want to ensure that a char is indeed an unsigned char then just cast it: static_cast<unsigned char>(some_char_value)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top