在c ++,c#,java中char的最小值是多少 [英] what is minimum value of char in c++, c#, java

查看:165
本文介绍了在c ++,c#,java中char的最小值是多少的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在32位计算机上读一本书char占用1个字节,范围是-128到127.

字符的ascii值是-128还是127?如果是,则127可以,但是-128是什么.请任何人让我理解.

问候,
Arshad Alam

i read in a book char take 1 byte on a 32 bit computer and its range is -128 to 127.

Is -128 or 127 is ascii value for a character? If Yes, Then 127 is ok, but What is -128. Please anyone make me understand.

Regards,
Arshad Alam

推荐答案

基本上1个字节表示8位,并且每个位都可以存储1或0.在无符号数字的情况下,第一个位用于存储+或-.可以存储在1个字节中的最小值是
-1111111(二进制),即7个1位,-的第一位),最大值为+1111111(二进制).现在,如果您进行转换,那么您将得到答案.
Basically 1 byte means 8 bit and every bit can store either 1 or 0. In case of un signed numbers first bit is used to store either + or - . There for the min value that can be store in 1 byte is
-1111111(in binary. i.e 7 1''s and first bit for -) and max is +1111111(in binary). Now if you convert then you will your answer.


正如John和Bob所提到的,字符没有符号.通常,NULL字符的字符值从零开始,然后增加到在定义的字符类型中可以保留的最大值.在此处提到的类型(一个字节)中,最大值为255,这允许总共256个字符(ASCII集).如果我没记错的话,Unicode(C#和Java的默认值)使用两个字节,总共为65536,而多字节字符最多占四个字节. 本文 [
As mentioned by John and Bob, a character does not have a sign. In general character values start at zero for the NULL character and increase to whatever maximum can be held in the defined character type. In the type you mention here (one byte) the maximum value is 255, which allows for a total of 256 characters (the ASCII set). Unicode (default for C# and Java) uses two bytes giving a total of 65536, and multi-byte characters take up to four bytes, if I remember correctly. This paper[^] provides some more detailed information.


此处是 ASCII表 [
Here''s an ASCII table[^], and as others have already stated, characters are unsigned.


这篇关于在c ++,c#,java中char的最小值是多少的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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