Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

ice88873

Unsigned char and char?

This topic is 6060 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Whats the difference between the two? And could it be the cause of a problem I have with storing characters in a text buffer (with unsigned char, the string can never go above 22 chars in length).

Share this post


Link to post
Share on other sites
Advertisement
Both are 8-bit data, so that''s a no to your question. ASCII characters are in the range 0 to 126 anyways.

The difference is that unsigned char ranges from 0 to 255, while signed char ranges from -128 to 127. Unqualified ''char'' may stand for one or the other depending on your compiler.

Share this post


Link to post
Share on other sites
quote:
Original post by Useless Hacker
Why on earth would you need a signed char?


Anytime you needed a signed byte. In C and C++, a char is always one byte.

--
The Dilbert Principle: People are idiots.

Share this post


Link to post
Share on other sites
quote:
Original post by superpeter
unicode use 2 byte for every character.


Correct, but unicode can't be held within a C++ "char". That's what a "wide char", wchar_t, is for.

quote:
Useless Hacker
Why not just use a byte then. Use chars for chars ('a', 'b') and bytes for numbers (1, 2, 3). Thats what I always do.



And how, in C or C++ code, do you propose to specify you want to "use a byte", unless it's by using char? A char *is a* byte.

--
The Dilbert Principle: People are idiots.


Edited by - SabreMan on February 18, 2002 9:10:14 AM

Share this post


Link to post
Share on other sites
quote:
Original post by Useless Hacker
Why not just use a byte then. Use chars for chars (''a'', ''b'') and bytes for numbers (1, 2, 3). Thats what I always do.


Windef.h, line 143
typedef unsigned char BYTE;

Share this post


Link to post
Share on other sites
(unsigned char)255 is equal to (unsigned char)-1

Chars will sort of "wrap around". I dont really see any merit in declaring an unsigned char because it finally makes no difference anyway, or at least i dont know of any.

Of note: ''A'' is the equal to (char)65.

Share this post


Link to post
Share on other sites
quote:
Original post by Promit
(unsigned char)255 is equal to (unsigned char)-1

Chars will sort of "wrap around". I dont really see any merit in declaring an unsigned char because it finally makes no difference anyway, or at least i dont know of any.


What about when the data you want to hold in an 8-bit char requires a range of 0-255?

quote:

Of note: ''A'' is the equal to (char)65.

...on ASCII systems.



--
The Dilbert Principle: People are idiots.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!