By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,414 Members | 1,057 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,414 IT Pros & Developers. It's quick & easy.

why use unsigned char ever.

P: n/a
Why do we ever need to use unsigned char? Any examples will help a lot.
Jul 19 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
dave wrote:
Why do we ever need to use unsigned char? Any examples will help a
lot.


Any time you need a so-called byte (do not mix it with octet, bytes can have
more than 8 bits). For example in preparing a bit-map command for a device,
which is driven by command bytes. Also buffers (usually command buffers)
for external devices or (binary) protocol are built using unsigned
characters.

Also please remember, that it is implementation defined if char (without
telling if it is signed or not) is signed or not! So on some architectures
the char used is in fact an unsigned char.

Attila aka WW
Jul 19 '05 #2

P: n/a
Attila Feher wrote:
Also please remember, that it is implementation defined if char
(without telling if it is signed or not) is signed or not! So on some
architectures the char used is in fact an unsigned char.


Not exactly. char and unsigned char are always distinct types, even on
systems where a char behaves the same as an unsigned char.

Jul 19 '05 #3

P: n/a
Rolf Magnus wrote:
Attila Feher wrote:
Also please remember, that it is implementation defined if char
(without telling if it is signed or not) is signed or not! So on
some architectures the char used is in fact an unsigned char.


Not exactly. char and unsigned char are always distinct types, even on
systems where a char behaves the same as an unsigned char.


Yes, they are distinct. That is why I did not say that its type is unsigned
char. :-)

A aka WW
Jul 19 '05 #4

P: n/a
dave wrote:
Why do we ever need to use unsigned char? Any examples will help a lot.


Example: You need a 1 byte unsigned value.

Maybe you need to explain your question a little better.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #5

P: n/a
On 14 Aug 2003 23:47:30 -0700, x4****@yahoo.com (dave) wrote:
Why do we ever need to use unsigned char? Any examples will help a lot.


One example is practical usage of the standard toupper function.

Jul 19 '05 #6

P: n/a

"Rolf Magnus" <ra******@t-online.de> wrote in message
news:bh*************@news.t-online.com...
Attila Feher wrote:
Also please remember, that it is implementation defined if char
(without telling if it is signed or not) is signed or not! So on some
architectures the char used is in fact an unsigned char.


Not exactly. char and unsigned char are always distinct types, even on
systems where a char behaves the same as an unsigned char.


Just to add that char, signed char and unsigned char are three distinct
types.

--
JS
Jul 19 '05 #7

P: n/a
dave wrote:
Why do we ever need to use unsigned char? Any examples will help a lot.


I use unsigned char when I need to access the smallest size unit,
with the full range of the unit.

On many platforms that I work on, CHAR_BITS (number of bits in a char),
is 8. The data I need to manipulate is in these units and has the
range of 0..255. I can read in a whole buffer then parse out
the data.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 19 '05 #8

P: n/a
dave wrote:

Why do we ever need to use unsigned char? Any examples will help a lot.


Unsigned char is guaranteed never to have trap values, and its values
are pure binary notation. You access any object as an array of unsigned
char to view its value representation.
Brian Rodenborn
Jul 19 '05 #9

P: n/a
Thomas Matthews wrote:

On many platforms that I work on, CHAR_BITS (number of bits in a char),
is 8.


That should be CHAR_BIT without an S.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.