C short type of memory analysis

#include <stdio.h> 
#include <limits.h> 
void main () { 

	// the printf ( "% D Short, int% D, Long% D", the sizeof (Short), the sizeof (int), the sizeof (Long )); 
	// 32-bit, 64-bit long int and are equivalent, all four bytes 
	// Short only 2 bytes, is generally used in the case of insufficient memory resources, such as the development of embedded 

	short shMax SHRT_MAX =; 
	Short shMin = SHRT_MIN; 
	the printf ( "% D shmax iS, iS shMin% D \ n-", shmax, shMin); 

	unsigned Short ushMax = USHRT_MAX; 
	// unsigned Short ushMin = USHRT_MIN; Short minimum value is unsigned 0 
	the printf ( "% D ushMAX IS,", ushMax);

	Analysis // short of memory 
	// short 2 bytes 16 1 1,111,111,111,111,111 first bit represents the sign bit, 0 is a positive number, a is negative, the effective data is 15 bits 
	// usigned short 2 words section 1 16 1,111,111,111,111,111 valid data bit is 16 
	@ Conclusion: the same 16 1, at different resolutions, a completely different meaning indicated 

	short x -1 =;
	the printf ( "The address of IS X% X", X &); 
	// - 1 is the original code 1,000,000,000,000,001 
	// - 1 is the inverted 1,111,111,111,111,110 
	@ - is a complement 1111 1111 1111 1111   
	@ 16 hex: ffff number memory representation 

	getchar (); 
}

 

Guess you like

Origin www.cnblogs.com/luoxuw/p/11220139.html