The Gateway to Computer Science Excellence
+21 votes
2.9k 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%}$
in Digital Logic by
edited by | 2.9k views

3 Answers

+39 votes
Best answer
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
edited by
+13
9999 in binary requires 14 bits. so, 2 bits are remaining and 1 we can use for sign.
0

I didn't get this please somebody explain.

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

0
Why are we not using BCD instead of binary?
0

Arjun sir, here integer size as 2B is an assumption???

0
Not an assumption - taking the minimum possible size required for an integer for the given problem.
+1

but @ Arjun Sir nowhere maximum reduction is mentioned, so how can we assume only 2B??

If I take 4B, then (5-4)/5 gives 20% savings. How to avoid such dilemma?

0
And 20 or 60 is maximum? :)
0
alright sir, thanks!
0

@meghna please help me with this line

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)

I AM NOT GETTING IT

0
@deepanshu 9999 can be represented with 14-bit(as 2^13=8192<9999 so 2^14=16384>9999) now 2-bit will be remaining so 1-bit will use for sign bit as MSB ,so approximately 15-bit (2 Byte) will require .

one Byte have 8-bit so 2^8=256 unique integers will be there and 2-byte have 16-bit so 2^16= 65536 unique address will be there.
0
@Arjun Sir @Anybody

First the field was stored as a char .

  To represent all SIGNED numbers of 4 bytes  we need 5 Bytes as one byte will store '+' or '-'

Now when we switch this field to int All int numbers are stored by default in 2's complement form.

2 's complement numbers have a range of -2^(n-1) to 2^(n-1)-1  so to be able to represent 9999

   2^(n-1)-1 >=9 .    --> 15 bits  

then??   why this 15 bits is taken as 16 bits aka 2 bytes ??
0
then how can represent 15 bits in Byte ? tell me
0

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

+5 votes
answer - C

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
by
0
You assumed 20K entries to be stored rt?
0
yes
0
Not getting it? how you get 5B to store each number?
+2 votes

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

by
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
52,345 questions
60,513 answers
201,931 comments
95,360 users