Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

No of bits necessary for the expression

Status
Not open for further replies.

sun_ray

Advanced Member level 3
Joined
Oct 3, 2011
Messages
772
Helped
5
Reputation
10
Reaction score
5
Trophy points
1,298
Activity points
6,828
How many bits ore necessary for L

L=MN + PQ + 2T

where M,N,Q,T are 16 bits and P is 8 bits.
 

L will need 33 Bits (Assuming they are unsigned numbers.)

L (bits) = Max ( 32bits , 24bits , 17bits ) + 1 (for carry)

Regards,
-Elecrom
 
Last edited by a moderator:

L will need 33 Bits (Assuming they are unsigned numbers.)

L (bits) = Max ( 32bits , 24bits , 17bits ) + 1 (for carry)

Regards,
-Elecrom

Can you please explain how you arrived this? How one carry will be sufficient?

Regards
 

Signed or unsigned? Will make a difference for the multiplies.
 

Signed requires less bits, so the number of bits given by #2 is the required number of bits.

Using a slightly different set of bit widths so it's easy to calculate stuff....
L=MN + PQ + 2T
where M,N,Q,T are 4 bits and P is 2 bits.

M*N is (4-bit)*(4-bit) unsigned the biggest 4-bit number is 15 (i.e. 0b1111) and 15*15 = 225 = 0xE1 (an 8-bit value) so multiplication adds the bit widths up...

therefore P*Q = (4-bit)*(2-bit) = 6-bit (i.e. 15*3)

multiplication by 2 is a shift in binary so 2*T is 5-bit. (i.e. 2*15)

When summing the total can exceed the maximum value of 0xFF, e.g. 225+45+30=300 (a 17-bit number, 0x12C)

So in this case L must be 17-bits.
 

Hi,

L=MN + PQ + 2T

where M,N,Q,T are 16 bits and P is 8 bits.

Unsigned:

M= 16 bits, N = 16 bits therfore MxN = 32 bits.
P = 8 bits, Q = 16 bits, therfore PxQ = 24 bits.
T = 16 bits, therfore 2 x T = 17 bits.

adding a 17 bit value to a 24 bit value give max a 25 bit value (one carry bit on a 24 bit value)

adding a 25 bit value to a 32 bit value gives max a 33 bit value (one carry bit on a 32 bit value)

Klaus
 

In order to have a visible illustration of what we are talking about...

Code:
#include <stdio.h>

void xbits(unsigned long long x){
	unsigned long long m = 1ull << (sizeof(m)*8-1);
	while(m){
		putchar((x & m) ? '1':'0');
		m>>=1;
	}
}

int main(void){
	unsigned long long m,n,p,q,t,r;
	m = n = t = q = 0xffff;
	p = 0xff;
	//r = (unsigned long long)-1;
	//printf("sizeof(r) == %u, r=%llx\n",sizeof r,r);
	r = m*n + p*q + 2*t;
	printf("%llx = ",r);
	xbits(r);
	return 0;
}

results printed:
Code:
100feff00 = 0000000000000000000000000000000100000000111111101111111100000000

33 bits max value (or 32 bits + 1 extra bit)
 

You need to be careful which language you use to write the expression as they all have different rules for width determination. T^he only reason you will get 33 bits is because the '2' in 2T is by default a 32-bit number.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top