0
\$\begingroup\$

Let us say I have a number with p bits:
x = [___...___] >> p Bits.
and I want to multiply it by another p bits.
will I receive:
x = = = [___...___...___] >> 2p Bits.
or:
x = = = [___...___...___] >> 2p-2 Bits.

EDIT: trying to explain better:
let us say I have a variable $X$.
x = some binary with has length of p bits ( if p=2, then X can be 00,01,10,11 ).
and I want to multiply the length of the bits of X ( p ) by another p.
Will I receive a variable x = 2p or x = 2p-2 ( and as said, length of 2p or 2p-2 )

\$\endgroup\$
4
  • \$\begingroup\$ What does '>>' signify; is that supposed to be a right shift? Are your numbers signed or unsigned? Please try to clean up the formatting of your question. It is very confusing as written. \$\endgroup\$ Commented Oct 12, 2022 at 18:18
  • \$\begingroup\$ the >> is not for right shift, just means that X has 2p bits ( amount ). I dont know how to explain it very much, but all I mean, if the length of X in binary, will be 2p bits or 2p-2 bits, if I multiply X by another p bit \$\endgroup\$ Commented Oct 12, 2022 at 18:19
  • 1
    \$\begingroup\$ Try some worst-case examples. What do you get if you multiply the largest 3-bit number by itself? Does the result need 6 bits or just 4 bits? \$\endgroup\$ Commented Oct 12, 2022 at 18:24
  • \$\begingroup\$ Oh It gave me 6 bits. I see. Thank you, didnt think of it :) \$\endgroup\$ Commented Oct 12, 2022 at 18:31

1 Answer 1

5
\$\begingroup\$

For unsigned binary numbers with \$p\$ bits, the largest positive number is equal to \$2^p -1\$. Multiplying two such values together gives a product equal to \$2^{2p} - 2^{p+1} + 1\$. Since the largest exponent of \$2\$ is \$2p\$ we will need \$2p\$ bits to represent the product.

For example, suppose \$p=3\$. The largest possible value is 7, and the largest possible product is 49 (\$2^6 - 2^4 + 1 = 64 - 16 + 1 = 49\$). In binary, \$49 = 110001\$, which takes 6 bits.

\$\endgroup\$
1
  • \$\begingroup\$ Great! you even proved it for me :) \$\endgroup\$ Commented Oct 12, 2022 at 19:08

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.