473,387 Members | 1,425 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,387 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 65798
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.