0% found this document useful (0 votes)
19 views2 pages

Integer Overflow and Data Type Storage

This is a document

Uploaded by

Qazi Qazi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views2 pages

Integer Overflow and Data Type Storage

This is a document

Uploaded by

Qazi Qazi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PF ASSIGNMENRT NO:02

Name: Qazi Mudasir Ahmed


Roll: 24P-0544

Problem 2

ii) Demonstrate what happens when an unsigned integer goes below zero and a
signed integer overflow.
ANSWER:
-a) When unsigned integers go below zero it will give largest positive value which is
4294967295.
b) when signed integers overflows it will give largest negative value which is - 2147483648.

Problem 3: -
An embedded system is using limited memory to store various sensor data
values. You need to determine the optimal data type for storing different
ranges of values efficiently.
1. If you have an unsigned char type, how many bits are required to
store its maximum value?
ANSWER: -
For unsigned char type to store its maximum value only eight (8) bits
are required which is equal to one (1) byte.

2. Now, suppose you need to store a combination of two maximum values of


unsigned char in a single variable without exceeding the size of an unsigned
int. How many bits would be required in total for this storage?

ANSWER: - If we have to store the combination of two maximum values of unsigned char type
in a single variable, we will require sixteen (16) bits which is equal to two (2) bytes.
As we know that unsigned int equals to four (4) bytes which is equal to thirty-two (32) [Link]
we will easily store two maximum combinations of unsigned char type in it.
PF ASSIGNMENRT NO:02
Name: Qazi Mudasir Ahmed
Roll: 24P-0544

3. Additionally, if you want to store three maximum values of unsigned char


in three separate variables, one of which is an unsigned short, another an
unsigned int, and the last one as an unsigned long, what is the minimum
number of bits required for each of these types?
ANSWER: - Unsigned short: Typically, an unsigned short is 16 bits. It can store values from 0
to 65,535. Since an unsigned char requires only 8 bits, it can easily fit in an unsigned short.
 Bits required: 16 bits for the unsigned short.
 Unsigned int: Typically, an unsigned int is 32 bits. It can store values from 0 to
4,294,967,295. An unsigned char (8 bits) can fit in an unsigned int.
 Bits required: 32 bits for the unsigned int.
 Unsigned long: An unsigned long is typically 32 or 64 bits (depending on the system).
For this example, we'll assume 32 bits (which is typical for most systems). An unsigned
char can fit in an unsigned long.
 Bits required: 32 bits for the unsigned long.
Summary:
 Unsigned char requires 8 bits.
 Storing two unsigned char maximum values requires 16 bits in total.
 The minimum number of bits required for:
o Unsigned short: 16 bits.
o Unsigned int: 32 bits.
o Unsigned long: 32 bits (assuming a 32-bit system).

You might also like