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.
 

elecrom

Junior Member level 3
Joined
Sep 24, 2007
Messages
25
Helped
3
Reputation
6
Reaction score
1
Trophy points
1,283
Location
Kharagpur
Activity points
1,472
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:

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
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
 

jbeniston

Advanced Member level 1
Joined
May 5, 2005
Messages
460
Helped
106
Reputation
214
Reaction score
73
Trophy points
1,308
Activity points
3,494
Signed or unsigned? Will make a difference for the multiplies.
 

ads-ee

Super Moderator
Staff member
Joined
Sep 10, 2013
Messages
7,919
Helped
1,821
Reputation
3,652
Reaction score
1,801
Trophy points
1,393
Location
USA
Activity points
59,952
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.
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
22,489
Helped
4,643
Reputation
9,302
Reaction score
4,941
Trophy points
1,393
Activity points
148,599
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
 

xenos

Full Member level 4
Joined
May 9, 2015
Messages
212
Helped
82
Reputation
164
Reaction score
81
Trophy points
28
Location
127.0.0.1
Activity points
1,182
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)
 

dave_59

Advanced Member level 3
Joined
Dec 15, 2011
Messages
826
Helped
364
Reputation
732
Reaction score
358
Trophy points
1,353
Location
Fremont, CA, USA
Activity points
6,942
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

Top