472,111 Members | 2,042 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,111 software developers and data experts.

why use unsigned char ever.

Why do we ever need to use unsigned char? Any examples will help a lot.
Jul 19 '05 #1
9 65528
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
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
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
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
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

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

Similar topics

7 posts views Thread by Alex Vinokur | last post: by
10 posts views Thread by Lars Tackmann | last post: by
3 posts views Thread by QQ | last post: by
42 posts views Thread by sarathy | last post: by
24 posts views Thread by Francine.Neary | last post: by
4 posts views Thread by HackerisNewKnight | last post: by
3 posts views Thread by Donos | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.