Solved

Unsigned usage?

Posted on 1999-01-14
5
350 Views
Last Modified: 2010-04-15
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
Comment
Question by:thiamwah
  • 2
  • 2
5 Comments
 
LVL 13

Accepted Solution

by:
Mirkwood earned 60 total points
ID: 1255893
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
 
LVL 84

Expert Comment

by:ozo
ID: 1255894
also relational operators
(and unsigned types never overflow)
0
 

Author Comment

by:thiamwah
ID: 1255895
"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
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1255896
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
 

Author Comment

by:thiamwah
ID: 1255897
thanks!

0

Featured Post

Integrate social media with email signatures

Is your company active on social media? Do you also use email signatures? Including social media icons in your email signature is a great way to get fans for free. Let all your email users know you’re on social media quickly and easily, in a single click.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to update multiple binary circular files in C 3 225
why "." vs "->" 23 119
Socket Programming (Unix) 8 119
Arduino EDI - Programming language 3 80
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now