• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 363
  • Last Modified:

Unsigned usage?

Hi,
  I am not sure what is unsigned char used for???
While I know when to differentiate usage of unsigned int/long and signed int/long, I don't see when to use unsigned and signed char? Can anybody explain to me in detial how to use unsigned and signed char (or generally) and when to use ..?

Thanks in advance
Thanks
0
thiamwah
Asked:
thiamwah
  • 2
  • 2
1 Solution
 
MirkwoodCommented:
An unsigned char is mostly referred to as a BYTE.
Its range goes from 0-255 while is signed char is
-128 to 127.
It all has to do how a the value should be interpreted by the compiler when converting it to e.g. a long and when the compiler reaches an overflow.

0
 
ozoCommented:
also relational operators
(and unsigned types never overflow)
0
 
thiamwahAuthor Commented:
"It all has to do how a the value should be interpreted by the compiler when converting it to e.g. a long "
can u give an example? A simple one would suffice. :)
0
 
MirkwoodCommented:
char t1;
unsigned char t2;
long l1;
long l2;

t1 = 127;
t2 = 127;
t1 *= 2;
t2 *= 2;
l1 = t1;
l2 = t2;
---
Result:
l1 gives either an overflow or becomes -2 (I think) or given an overflow.
l2 becomes 254

Bitwise shift operations give also nice results.


0
 
thiamwahAuthor Commented:
thanks!

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now