Data types are used to represent numbers and characters used in a program, why do programmers benifit from having such a variety? Also if anyone could help me out with what an unsigned character is used for?

thanks for the help

Recommended Answers

All 2 Replies

Tipically a char is 8-bit long, and most significant bit(MSB) represent the sign value.
If MSB is 0, it means positive and if MSB is 1, it means negative.

So only last 7 bits (out of 8 bits) are used to store the actule char value. And total number of values will be 2^7 = 128 (0 to 127) or (-128 to 0).
But when we declare a char as unsigned then there is no importance of the sign bit (i.e MSB), So now total value stored in char will be 2^8 = 256 (0 to 255), and this will cover all the char values.

One of important use of unsigned char is in embedded system, to store the value of some 8-bit register.

>why do programmers benifit from having such a variety?
They can choose the data type that best fits the problem and optimize speed or storage costs.

>Also if anyone could help me out with what an unsigned character is used for?
Off the top of my head: If you don't want negative numbers, if you want to extend the range of signed char but don't want to jump up to short int, if you need the wrap-around qualities of an unsigned type, if you want to store an object in an array of bytes (unsigned char is the only type guaranteed not to have padding bits).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.