473,386 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 65797
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Alex Vinokur | last post by:
I came across the following piece of code: #define ERROR -1 #define STATUS0 0 #define STATUS1 1 #define STATUS2 2 unsigned char foo() { if (/* condition-A */) return ERROR; /* is that...
10
by: Lars Tackmann | last post by:
Does the c standard state that for all c99 implementation char as standard is equal unsigned char ??? - or do i have to take this into account when writing my program ???.
3
by: QQ | last post by:
Hello, Here is my simple program int main() { unsigned char a =0x81; char b = 0x81; printf("unsigned char = 0x%x(%d), char = 0x%x(%d)\n",a,a,b,b); printf("cast char to unsigned...
42
by: sarathy | last post by:
Hi, I need clarification regarding signed characters in the C language. In C, char is 1 byte. So 1. Unsigned char - ASCII CHARACTER SET - EXTENDED CHARACTER SET
24
by: Francine.Neary | last post by:
I've read that you should always cast the argument you pass to isupper(), isalnum(), etc. to unsigned char, even though their signature is int is...(int). This confuses me, for the following...
4
by: HackerisNewKnight | last post by:
Hello, 1) First problem. In my project i need to convert from char* to BYTE*( BYTE is unsigned char), is there any way to make the convertion? BYTE* bite; char* ch="help me, please"; bite =...
3
by: Donos | last post by:
Hello I have the following program, void getValue(unsigned char* pVal) { pVal = allValues(); } unsigned char* allValues()
29
by: Kenzogio | last post by:
Hi, I have a struct "allmsg" and him member : unsigned char card_number; //16 allmsg.card_number
8
by: KYAW KYAW OO | last post by:
Dear All, Now, I am stuck above question so long and I would like to get Red, Green and Blue as unsigned char * each from unsigned char * of 24 bit BMP Color images. e.g unsigned char *...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.