1、系统级编程作业 lab1解析System Level Programming Lab C+ fundamentals and Type conversion Student ID _1043111051_ Student Name 王金科_ _ Start Time 16:20星期二日 2012年09月4 Finish Time 23:55 星期日09月9日2012年1. Objectives: To write simple C+ programs covering: ? Understand how a character is stored in memory; ? Understand
2、 how an integer is stored in memory; ? Understand array and pointer; and ? Perform conversion from eight bits (character) to eight bytes to be displayed on screen. 2. Type and Format in memory character, integer, short and float 2.1 This exercise is to determine the memory size of different type. la
3、b1_1.cpp /Determine the memory size of declaration and variable type #include #include #include #include #include #include void main() char c; char s128; short i; short n64; printf(= =n, sizeof(c), sizeof(char); printf(= =n, sizeof(s), sizeof(char128); printf(= =n, sizeof(i), sizeof(short); printf(=
4、 =n, sizeof(n), sizeof(short64); The display is: 1 - - 2018/10/21 System Level Programming Lab Now execute the above program and fill in the following: Size in bit Size in byte Type 16 2 Short 8 1 Char 64 512 Short32 64 512 Char64 2.2 integer128, integer, float, the Use the approach of the above, de
5、termine memory size of float16 (lab1_2.cpp) ) Write a program to verify your answer and fill in the following: hint, use sizeof(Size in bit Type Size in byte 32 4 Int 32 4 Float 512 4096 Int128 512 64 Float16 Write down your codes below: #include #include #include #include #include #include void mai
6、n() int c; int s128; float I; float n16; printf(“=n”,sizeof(c),sizeof(int); printf(“=n”,sizeof(s),sizeof(int128); printf(“=n”,sizeof(i),sizeof(float); printf(“=n”,sizeof(n),sizeof(float16); Write down your expression amongst the difference in size between character, integer, float, short, char8, int
7、8, short8, float8 Character = 1 byte Integer = 4bytes Float = 4bytes Short = 2bytes Char8 = 8bytes Int 8 = 32bytes Short8 = 16bytes Float8 = 32bytes 2 - - 2018/10/21 System Level Programming Lab 2.3 This exercise is to display the decimal and octal values so that you know how it is stored in memory.
8、 lab1_3.cpp /Determine the memory size of declaration and variable type #include #include #include #include #include #include void main() for (char i = 30; i 41; +i) printf(i: dec=%d oct=%o n, i, i); the output is: well. unsigned as hex to the above programme display decimal, octal, and modify Now (
9、Hints: hex, %x, unsigned %u) Write down your codes below: #include #include #include #include 3 - - 2018/10/21 System Level Programming Lab #include #include void main() for(char i = 30; i 41;+i) printf(i: dec=%d oct=%o hex=%x unsigned=%u n, i, i,i,i); Write down the output of the first 4 lines so t
10、hat you understand the difference among them. i:dec=30 oct=36 hex=1e unsigned=30 i: dec=31 oct=37 hex=1f unsigned=31 i: dec=32 oct=40 hex=20 unsigned=32 i: dec=33 oct=41 hex=21 unsigned=33 2.4 This exercise is to dump the content of memory of different type so that you know how it is stored in memor
11、y. lab1_4.cpp /Determine the memory size of declaration and variable type #include #include #include #include #include #include void main() char a = 0; / in hex 0x30, not 0 int i = 0x00000013; /in decimal is (1 x 16 + 3) = 19 short j = 18; /occupies two bytes, float f = 1.25; /occupies 4 bytes In or
12、der to display, you have to set a break point by pressing “F9” beside the line, the program will display a red circle as follows: 4 - - 2018/10/21 System Level Programming Lab Now, type the address of each variable as shown in the left-bottom frame to locate whether . Since, visual C+ reserves 4 byt
13、es but they are. Here, we dump the address of variable a(means CC to three see byte, you can that the rest bytes are set CC CC one c char uses 10101010 10101010 10101010 in binary, the default setting). &a is 0x0065fdf4, you have to type 1memory location of athen in the Address, key in 0x0065fdf4, 2it displays 30 CC CC CC 3 0x0065FDF4, the hexadecimal is 0x30 (ASCII) 5 - - 2018/10/21 System Level Programming Lab Now, type and execute the above program and fill in the following, note th
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1