unsigned char的含义 [英] Meaning of unsigned char

查看:126
本文介绍了unsigned char的含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要澄清有关C

语言的签名字符。


在C中,char为1字节。所以


1.未签名的字母


[0到127] - ASCII字符集

[128到255 ] - 扩展字符集


2.签名字符

[-128到0] - ?????

[ 0到127] - ASCII字符集


字符签名意味着什么?签名和未签名的char之间是否存在

的差异?如果是,那么它们如何与b $ b不同。如果不是,那么为什么C标准没有将char数据限制为单独的无符号。


我一直在指各种文章,但是徒劳无功。任何帮助都会非常感激。


问候,

Sarathy

Hi,
I need clarification regarding signed characters in the C
language.

In C, char is 1 byte. So

1. Unsigned char

[0 to 127] - ASCII CHARACTER SET
[128 to 255] - EXTENDED CHARACTER SET

2. Signed char
[-128 to 0] - ?????
[0 to 127] - ASCII CHARACTER SET

What does it mean for a character to be signed ? Is there any
difference between signed and unsigned char ? If Yes, how do they
differ. If No, then why didnt the C standard restrict the char data
type to unsigned alone.

I have been referring to various articles, but in vain. Any help would
be greatly appreciated.

Regards,
Sarathy

推荐答案

sarathy写道:
sarathy wrote:



我需要澄清有关签名的字符C $ / b $ b语言。


在C中,char是1个字节。所以
Hi,
I need clarification regarding signed characters in the C
language.

In C, char is 1 byte. So



在C中,字符和字节是/同样的东西/,并且不需要只有8位宽的

In C, characters and bytes are /the same thing/, and need not by only
8 bits wide.


1.无符号字符

[0到127] - ASCII字符集
1. Unsigned char

[0 to 127] - ASCII CHARACTER SET



C不需要ASCII。

C doesn''t require ASCII.


[128到255] - EXTENDED CHARACTER SET
[128 to 255] - EXTENDED CHARACTER SET



C对扩展字符集一无所知。

(无论如何都不在C语言环境中。)

C doesn''t know anything about "the extended character set".
(Not in the C locale, anyway.)


2.签名字母

[-128到0] - ?????

[0到127] - ASCII字符集
2. Signed char
[-128 to 0] - ?????
[0 to 127] - ASCII CHARACTER SET



主要是dittos。


C /确实/说是C定义的字符为正,

如果我没记错。

Mostly dittos.

What C /does/ say is that the C-defined characters are positive,
if I recall correctly.


签名角色是什么意思?
What does it mean for a character to be signed ?



类型`signed char`的值可能是负数。类型值

` unsigned char`不能为负数。类型`char`相当于

到其中一个(但不是/同一类型/)。

A value of type `signed char` may be negative. A value of type
`unsigned char` cannot be negative. The type `char` is equivalent
to one of them (but is not the /same type/).


有什么区别签名和未签名的char之间?
Is there any difference between signed and unsigned char ?



是,如上所述。

Yes, as above.


如果是,它们有何不同。
If Yes, how do they differ.


如果否,那么为什么C标准没有将char数据限制为单独的无符号
类型。
If No, then why didnt the C standard restrict the char data
type to unsigned alone.



因为当C标准化时,某些实现已经签署了
char,而有些实例则使用无符号字符。所以

char是不明确的,另外两种口味是

介绍允许程序员明确。


-

Chris" seeker" Dollin

这里没有人正是他出现的。 G''kar,/ Babylon 5 /

Because when C was standardised, some implementations had
char being signed, and some had char being unsigned. So
char was left ambiguous and the two other flavours were
introduced to allow the programmer to be explicit.

--
Chris "seeker" Dollin
"No-one here is exactly what he appears." G''kar, /Babylon 5/


sarathy发布:
sarathy posted:



我需要澄清C

语言中的签名字符。


在C中,char是1个字节。
Hi,
I need clarification regarding signed characters in the C
language.

In C, char is 1 byte.



是的。一个字节中的位数可以从CHAR_BIT

宏中确定。


Yes it is. The amount of bits in a byte can be determined from the CHAR_BIT
macro.


所以


1.未签名的字符


[0到127] - ASCII字符集

[128到255] - EXTENDED CHARACTER SET
So

1. Unsigned char

[0 to 127] - ASCII CHARACTER SET
[128 to 255] - EXTENDED CHARACTER SET



所有C关心的是:


(1)sizeof(char unsigned)== 1


(2)最小范围:0到255


All C cares about is this:

(1) sizeof(char unsigned) == 1

(2) Minimum range: 0 through 255


2.签名字母

[-128到0] - ?????

[0到127] - ASCII字符集
2. Signed char
[-128 to 0] - ?????
[0 to 127] - ASCII CHARACTER SET



所有C关心的是:


(1)sizeof(字符签名)== 1


(2)最小范围:-127到127


All C cares about is this:

(1) sizeof(char signed) == 1

(2) Minimum range: -127 through 127


签名字符是什么意思?
What does it mean for a character to be signed?



它可以存储负值。


It can store a negative value.


签名和之间是否有任何区别无符号的字符 ?
Is there any difference between signed and unsigned char ?



它们都是整数类型,就像int,short一样。和长。请参阅上面的

最小范围。


They''re both integer types, just like "int", "short" and "long". See their
minimum range above.


如果是,它们有何不同。
If Yes, how do they differ.



他们的签名(以及他们的范围)不同。


They differ in their signedness, (and consequently, their range).


如果否,那么为什么C标准没有将char数据限制为单独的无符号。
If No, then why didnt the C standard restrict the char data
type to unsigned alone.



用于存储字符的类型是char。它是实现

定义的是普通字符是签名还是未签名。使用普通字符算术或存储数字是没有好理由的。


" unsigned char"是无符号整数类型。


" signed char"是一个有符号整数类型。


在我看来,你对它的名字感到困惑。是的,事实上它是'/ b $ b'被称为char建议它可能不仅仅是一个简单的整数类型,而是

它。


-


Frederick Gotham


The type used for storing characters is "char". It is implementation
defined as to whether a plain char is signed or unsigned. There''s no good
reason to use a plain char for arithmetic or storing numbers.

"unsigned char" is an unsigned integer type.

"signed char" is a signed integer type.

It seems to me that you''re confused by its name. Yes, the fact that it''s
called "char" suggests that it might not just be a simple integer type, but
it is.

--

Frederick Gotham


" sarathy" < sp ********* @ gmail.comwrites:
"sarathy" <sp*********@gmail.comwrites:

我需要澄清有关C中签名字符的信息
语言。


在C中,char是1个字节。所以


1.未签名的字母


[0到127] - ASCII字符集

[128到255 ] - 扩展字符集


2.签名字符

[-128到0] - ?????

[ 0到127] - ASCII字符集


字符签名意味着什么?签名和未签名的char之间是否存在

的差异?如果是,那么它们如何与b $ b不同。如果否,那么为什么C标准没有将char数据限制为单独的无符号。
I need clarification regarding signed characters in the C
language.

In C, char is 1 byte. So

1. Unsigned char

[0 to 127] - ASCII CHARACTER SET
[128 to 255] - EXTENDED CHARACTER SET

2. Signed char
[-128 to 0] - ?????
[0 to 127] - ASCII CHARACTER SET

What does it mean for a character to be signed ? Is there any
difference between signed and unsigned char ? If Yes, how do they
differ. If No, then why didnt the C standard restrict the char data
type to unsigned alone.



char是一个字节的定义,具体来说,是字符byte的C标准'/ b $ b定义。这并不一定符合

这个单词byte的方式。在其他上下文中使用。


一个字节中的位数由

< limits.h>中的常量CHAR_BIT指定。它必须至少为8,但它可以更大。 (你不是可能会遇到CHAR_BIT 8的系统,除非你使用

嵌入式系统,特别是DSP,但是你仍然不应该假设

,CHAR_BIT == 8。)


char,signed char和unsigned char都是整数类型,能够代表
某些范围内的整数值。对于签名字符,

范围至少为-127到+127。对于unsigned char,它至少是
0到255. char的范围匹配其中一个范围。


这些数字类型可以(和经常用于存储字符

值,有时是ASCII,有时是其他一些编码。如果

编码指定字符0到127的含义,就像ASCII那样,

那么那些数字字符值将与这些字符对应。

该范围之外的数字值可能没有任何指定含义

作为字符,但它们仍然完全有效作为数值。


-

Keith Thompson(The_Other_Keith) ks***@mib.org < http://www.ghoti .net / ~kst>

圣地亚哥超级计算机中心< *< http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。

A char is one byte by definition, specifically, by the C standard''s
definition of the word "byte". This doesn''t necessarily match the way
the word "byte" is used in other contexts.

The number of bits in a byte is specified by the constant CHAR_BIT in
<limits.h>. It must be at least 8, but it can be larger. (You''re not
likely to run into systems with CHAR_BIT 8, unless you work with
embedded systems, particularly DSPs, but you still shouldn''t assume
that CHAR_BIT==8.)

char, signed char, and unsigned char are all integer types, capable of
representing integer values within certain ranges. For signed char,
the range is at least -127 to +127. For unsigned char, it''s at least
0 to 255. The range of char matches one of those ranges.

These numeric types can (and very often are) used to store character
values, sometimes ASCII, sometimes some other encoding. If the
encoding specifies the meanings of characters 0 to 127, as ASCII does,
then those numeric char values wiill correspond to those characters.
Numeric values outside that range may not have any specified meaning
as characters, but they''re still perfectly valid as numeric values.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


这篇关于unsigned char的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆