Главная

les-grizzlys-catalans.org Reference Language Basics Data Types Integer Types Char, Short, Int and Long Types

 Char, Short, Int and Long Types Char, Short, Int and Long TypescharThe char type takes 1 byte of memory (8 bits) and allows expressing in the binary notation 2^8=256 values. The char type can contain both positive and negative values. The range of values is from -128 to 127.You are watching: How many bits are in a characterucharThe uchar integer type also occupies 1 byte of memory, as well as the char type, but unlike it uchar is intended only for positive values. The minimum value is zero, the maximum value is 255. The first letter u in the name of the uchar type is the abbreviation for unsigned.shortThe size of the short type is 2 bytes (16 bits) and, accordingly, it allows expressing the range of values equal to 2 to the power 16: 2^16 = 65 536.Since the short type is a signed one, and contains both positive and negative values, the range of values is between -32 768 and 32 767.ushortThe unsigned short type is the type ushort, which also has a size of 2 bytes. The minimum value is 0, the maximum value is 65 535.intThe size of the int type is 4 bytes (32 bits). The minimal value is -2 147 483 648, the maximal one is 2 147 483 647.uintThe unsigned integer type is uint. It takes 4 bytes of memory and allows expressing integers from 0 to 4 294 967 295.longulongExamples:charch=12;shortsh=-5000;intin=2445777;

Since the unsigned integer types are not designed for storing negative values, the attempt to set a negative value can lead to unexpected consequences. Such a simple script will lead to an infinite loop:

 //---InfiniteloopvoidOnStart()ucharu_ch;for(charch=-128;chu_ch=ch;Print("ch=",ch,"u_ch=",u_ch);

The correct variant is:

 //---CorrectvariantvoidOnStart()ucharu_ch;for(charch=-128;chu_ch=ch;Print("ch=",ch,"u_ch=",u_ch);if(ch==127)break;

Result:

 ch=-128u_ch=128ch=-127u_ch=129ch=-126u_ch=130ch=-125u_ch=131ch=-124u_ch=132ch=-123u_ch=133ch=-122u_ch=134ch=-121u_ch=135ch=-120u_ch=136ch=-119u_ch=137ch=-118u_ch=138ch=-117u_ch=139ch=-116u_ch=140ch=-115u_ch=141ch=-114u_ch=142ch=-113u_ch=143ch=-112u_ch=144ch=-111u_ch=145...See more: Where Is Captain Stern In Pokemon Ruby ? Where Is Captain Stern For The Scanner

Examples:

 //---Negativevaluescannotbestoredinunsignedtypesucharu_ch=-120;ushortu_sh=-5000;uintu_in=-401280;

Hexadecimal: numbers 0-9, the letters a-f or A-F for the values of 10-15; start with 0x or 0X.