Lab Hands On 2 - Data Representation Part 1 (AKIA)
Lab Hands On 2 - Data Representation Part 1 (AKIA)
LBYCMSY
x or X : Hexadecimal integer
Procedures
1. Using a browser, research on the Internet the size of the following data types in the C programming
language:
Data Type Data Size (bits)
Short : 16 bits
Unsigned Short : 16 bits
Int : 32 bits
Unsigned Int : 32 bits
1
3. Write down the size of the following data types of the C programming language from the output of the
previous program:
Data Type Data Size (bits)
Short : 16 bits
Unsigned Short : 16 bits
Int : 32 bits
Long : 32 bits
4. Using pen and paper method, determine the range of the data type:
Upper Range Lower Range
16-bit Short : 32,767 -32,767
Yes
5. Is the information from the Internet the same with the output of the program? ___________________
6. What is the implication of the number of bits of a data type in relation to data size and range?
In summary, the number of bits in a data type affects the size of the data in memory, the range of
values it can represent, the precision of representation, and the performance of operations involving
that data type. The selection of an appropriate data type depends on the requirements of the specific
application, considering factors such as memory usage, range of values, and computational efficiency.
7. Using pen and paper method (calculators are allowed), write down the value in hexadecimal (write
down XXX if cannot be represented):
Value 32-bit Signed Integer 32-bit Unsigned Integer
234 : EA EA
2
8. Using Dev C++ compiler, execute the program and enter values from the previous procedure:
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or
input loop */
int a;
return 0;
}
10. Did the program output mathematically correct values for signed integer? Why?
3
11. Did the program output mathematically correct values for unsigned integer? Why?
It interprets the bits of the signed integer as an unsigned integer making changes in the representation
13. Analyze the program below and determine the output if the value to be entered for variable “a“ is
32767 (Note: Do not execute yet!):
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or
input loop */
short a;
a=a+1;
return 0;
}
32768
14. What is the probable value of variable “a” after the code “a=a+1” in the program? ________________
15. Calculate for the binary value of 32767 in the specified notation. Write down the probable display
value of the program:
Value Signed Integer Output Unsigned Integer Output Hexadecimal Output
4
16. Execute the program in procedure no. 13 using Dev C++ and write down the output:
Value Signed Integer Output Unsigned Integer Output Hexadecimal Output
17. Is the output of the C program for signed integer correct? Was there an overflow? Why?
Yes but there is an overflow because of the line code "a=a+1" and the maximum value for signed
short is only 32767.
18. Is the output of the C program for unsigned integer correct? Why is the output such a high value?
Yes. The outcome of the output is because it's converted into it's positive equivalent by %u.
19. Analyze the program below and determine the output if the value to be entered for variable “a“ is
32767 (Note: Do not execute yet!):
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or
input loop */
unsigned short a;
a=a+1;
return 0;
}
5
20. Execute the program in procedure no. 19 using Dev C++ and write down the output:
Value Signed Integer Output Unsigned Integer Output Hexadecimal Output
Yes
21. Is the output of the C program different from the earlier program? _____________
22. Explain why the program has a different output from before?
It's different because we are now using the unsigned short data type which is different from signed
short data type.
23. Run the program in procedure no. 19 and use the value 65535 as the input. Write down the result of
the output.
Value Signed Integer Output Unsigned Integer Output Hexadecimal Output
65357 65357 FF4D
65356 :
24. Is the output of the program different from last time? Explain why.
Yes because the range of signed and unsigned short is different which is causing the output of the
program to be different from one another.
25. What can you conclude from the output of the programs in procedure no.8, 13, and 19 in relation to
data size, range, accuracy and overflow?
What I can conclude from this activity is that we need to be careful in assigning numbers to different
data types because it may result to overflow or inconsistencies in the output of the program because
of the limitations of each data types in range.
26. How and why should you take data size into account when writing programs?
Taking data size into account is essential for writing efficient, portable, and correct programs.
It involves choosing appropriate data types based on the requirements of your program and
understanding how data is represented in memory on the target platform.