5,539 views

Suppose the domain set of an attribute consists of signed four digit numbers. What is the percentage of reduction in storage space of this attribute if it is stored as an integer rather than in character form?

1. $\text{80%}$
2. $\text{20%}$
3. $\text{60%}$
4. $\text{40%}$

I assume byte addressable memory- nothing smaller than a byte can be used.

We have four digits. So, to represent signed 4 digit numbers we need 5 bytes- 4 for four digits and 1 for the sign (like -7354). So, required memory = 5 bytes

Now, if we use integer, the largest number needed to represent is 9999 and this requires 2 bytes of memory for signed representation (one byte can represent only 256 unique integers).

So, memory savings while using integer is $\frac{(5 - 2)}{5} = \frac{3}{5} = 60\%$

Correct Answer: $C$
by

@rahul sharma 5 BCD would take more space than regular binary, even if it is more convenient.

Note:

Here if we store “-7354” in form of characters, in “-7354” there are 5 characters : $\{ \ ’- ’,’7’,’3’,’5’,’4’\}$

So for each character we need 1 byte. Therefore total memory reqd for 5 characters → 5B

Here if we store $-7354$ in form of numbers, in $-7354$ the number $7354$ as integer will require $14$ bits to be represented (as $2^{13} = 8192$) we can take one more bit  to store sign (e.g. it’s -ve no. so we will use $1$ to represent it). Thus in total we need $15$ bits ≈ $2B$.

Therefore reduction = $5B-2B = 3B$

%redn = $3B/5B*100 = 60\%$

signed four digit numbers

First position for the sign, the subsequent four positions for the digits.

__ __ __ __ __

It is common knowledge that 1 char takes 1 Byte. So, this will take 5 Bytes.

The size of int back in the day was 2 Bytes. Now it can take 4 Bytes with modern compilers. Since this is a 1998 question, let's assume the size of int is 2 Bytes :P So, this whole integer takes 2 Bytes.

Now the easiest part:

$\frac{5-2}{5}*100\%$

=> $60 \%$

Option C

Dennis Ritchie, Page number 36:

char [...] a single byte

and [the size of an] int [is] either 16 or 32 bits

### 1 comment

Perfect!

numbers stored as characters

total numbers to be represented 20K

each number represented using 5B

total space required 100KB

numbers stored as integers

every number can be represented using 2B

total space required 40KB

saving 60KB

You assumed 20K entries to be stored rt?
yes
Not getting it? how you get 5B to store each number?

1
6,258 views