954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Data Types

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

Drake
Newbie Poster
20 posts since Jun 2005
Reputation Points: 9
Solved Threads: 0
 

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.

Luckychap
Posting Pro in Training
444 posts since Aug 2006
Reputation Points: 83
Solved Threads: 61
 

>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).

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You