Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


Give a fast way to multiply a number by 7

Answers were Sorted based on User's Feedback



Give a fast way to multiply a number by 7..

Answer / thejonath

int i=2,j;
j=i;
i=(i<<3)-j;

Is This Answer Correct ?    100 Yes 15 No

Give a fast way to multiply a number by 7..

Answer / anu

Both answers have slight mistakes in them.
x *7 = ( x<<3 ) - x , which is equivalent to (x* 8 ) -x

Is This Answer Correct ?    65 Yes 6 No

Give a fast way to multiply a number by 7..

Answer / rajan

ANU is right the answer is x<<3 -x
when you left shift any number by 1 it is equivalent to
multiplying with 2.
so, left shift by 3 means ur are multiplying with 8.
and x*7 = x(8-1) = x*8-x = x<<3-x .

Is This Answer Correct ?    31 Yes 5 No

Give a fast way to multiply a number by 7..

Answer / anonymous

The easiest way is to relate the number to be multiplied
by, to a power of 2. Then a corresponding number of left
shifts to that power with an addition or subtraction would
give the desired result.

In this case, 7 can be written as 2^3 - 1 or 8 - 1.
Therefore, shift the number to the left thrice which would
multiply it by 8. Then subtract the original. You can also
do this as

4 + 2 + 1 = 2^2 + 2^1 + 1

Is This Answer Correct ?    20 Yes 6 No

Give a fast way to multiply a number by 7..

Answer / pratik chopra

Yes this can be made generic;
Approach: 7*x=(8-1)*x= 8*x-1*x=x<<3-x

If 6*x=(4+2)x=4*x+2*x=x<<2+x<<1
If 13*x=(16-2-1)x=(x<<4-x<<1-x)

Is This Answer Correct ?    8 Yes 0 No

Give a fast way to multiply a number by 7..

Answer / pratik chopra

It is very obvious above condition will not work if output
after multiplying by 7 is not 8 bit. In that case, if you
consider 64*7=448 which is 111000000 and a 9bit number.
Thus, there is an overflow. Even a normal decimal
calculation, restricted to 8 bit will not give a right answer.

In other words, any n-bit number whose multiplication with 7
is an n-bit number, the above solution will work otherwise,
overflow will occur.
For 8 bit no. max x<=(255/7)<=36.

Is This Answer Correct ?    7 Yes 1 No

Give a fast way to multiply a number by 7..

Answer / pathfinder

it shall be
n*7 = (n << 3) - n as already have been suggested by some ppl.

Is This Answer Correct ?    7 Yes 3 No

Give a fast way to multiply a number by 7..

Answer / shiva

x=(x<<3)-x;

Is This Answer Correct ?    3 Yes 0 No

Give a fast way to multiply a number by 7..

Answer / rupesh

There is a problem with
x=(x<<3)-x;
Suppose that x is stored in 8 bit format.
If x = 64, i.e. 2^6, then this won't work.
In general, if x is n-bit, and value of x > 2^(n-3), then
this won't work.

Is This Answer Correct ?    4 Yes 2 No

Give a fast way to multiply a number by 7..

Answer / ranjan

n<<3-n

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

How can you be sure that a program follows the ANSI C standard?

0 Answers   Aspire, Infogain,


array of pointer pointer to array pointer to pointer

1 Answers   MAHINDRA,


What is the difference between typedef struct and struct?

0 Answers  


find second largest element in array w/o using sorting techniques? use onle one for loop.

15 Answers   BitWise, Zycus Infotech,


What is the size of array float a(10)?

0 Answers  


Write a Program to accept different goods with the number, price and date of purchase and display them

0 Answers   HDFC,


Develop a program that computes the new price of an item. The program should receive a character variable colour and a double precision floating-point variable price from the user. Discount rate is determined based on the colour of the discount sticker, as shown in the following table. An error message should be printed if an invalid colour has been entered

1 Answers  


How can a program be made to print the name of a source file where an error occurs?

0 Answers  


Define recursion in c.

0 Answers  


What is the meaning of 2d in c?

0 Answers  


Iam a B.Tech graduate and completed my engineering in 2009, from 2005 to 2009 and after that i had done nothing.Now i want to do job and get into BPO field . Friends give me suggestions as what to say in interview... if they ask me that what would you had done ... these many years without doing job ??????? pls urgent

0 Answers  


What are the preprocessor categories?

0 Answers  


Categories