Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > why use unsigned char ever.

Reply
Thread Tools

why use unsigned char ever.

 
 
dave
Guest
Posts: n/a
 
      08-15-2003
Why do we ever need to use unsigned char? Any examples will help a lot.
 
Reply With Quote
 
 
 
 
Kevin Goodsell
Guest
Posts: n/a
 
      08-15-2003
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.

 
Reply With Quote
 
 
 
 
Attila Feher
Guest
Posts: n/a
 
      08-15-2003
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


 
Reply With Quote
 
Rolf Magnus
Guest
Posts: n/a
 
      08-15-2003
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.

 
Reply With Quote
 
Attila Feher
Guest
Posts: n/a
 
      08-15-2003
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


 
Reply With Quote
 
Alf P. Steinbach
Guest
Posts: n/a
 
      08-15-2003
On 14 Aug 2003 23:47:30 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) (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.

 
Reply With Quote
 
Josephine Schafer
Guest
Posts: n/a
 
      08-15-2003

"Rolf Magnus" <(E-Mail Removed)> wrote in message
news:bhi7he$9hr$05$(E-Mail Removed)-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


 
Reply With Quote
 
Thomas Matthews
Guest
Posts: n/a
 
      08-15-2003
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

 
Reply With Quote
 
Default User
Guest
Posts: n/a
 
      08-15-2003
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
 
Reply With Quote
 
Kevin Goodsell
Guest
Posts: n/a
 
      08-16-2003
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Casting from const pair<const unsigned char*, size_t>* to constpair<unsigned char*, size_t>* Alex Vinokur C++ 9 10-13-2008 05:05 PM
Padding bits and char, unsigned char, signed char Ioannis Vranos C++ 11 03-28-2008 10:47 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Linking error LNK2001 - "__declspec(dllimport) private: void __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::_Tidy(unsigned short)" (__imp_?_Tidy@?$basic_string@DU?$char_ sharmadeep1980@gmail.com C++ 1 07-07-2006 07:27 AM
void*, char*, unsigned char*, signed char* Steffen Fiksdal C Programming 1 05-09-2005 02:33 AM



Advertisments