Write the equivalent expression for x%8?

X&7 Write expressions to swap two integers without using a temporary variable?

Showing Answers 1 - 18 of 18 Answers

Munish Chandel

  • Apr 13th, 2006
 

x^=y;y^=x;x^=y;y^=x;

  Was this answer useful?  Yes

Angy

  • Sep 13th, 2006
 

i have tried but welll i just cant crack it

  Was this answer useful?  Yes

Preetham

  • Sep 26th, 2006
 

while(x>8)

{

x=x-8;

}

printf("%d",x);

u will get the remainder

  Was this answer useful?  Yes

fchen

  • Jul 10th, 2007
 

oops, my prev answer was wrong :D
x & 7 is the answer :)
I would rather write it as:
x & 0x07

the q "

Write expressions to swap two integers without using a temporary variable?" sounds interesting ...

  Was this answer useful?  Yes

Arijit

  • Jul 10th, 2007
 

swapping of two variables:-
int a=10;
int b=20;
a=a+b;
b=a-b;
a=a-b;

[:)]

Sandeep Sutar

  • Aug 19th, 2007
 

Just x%8 means the last 3 bits of the integer i.e if x= 1100 1101  in binary the x%8 = 101 in binary. So any algo or step will go this.for example: =(x-(x>>3)*8)
 
in x>>3 losses the 3 bit and multiplying by 8 replace last 3 bits by 000 and after subtracting we get the bit

x == 1100 1101
x>>3 == 0001 1001
x*8 == 1100 1000
x-above no == 101

all no in binary.

  Was this answer useful?  Yes

som thomas

  • Oct 14th, 2007
 

u can try dis
float y;
int z;
while(x>8)
{
  y=x/8; //y will  also have decimal values
  z=x/8; //z will only have integer values
  y=y-z;// y will have only decimal parts
 z=y*8;// we will have reminder value stored in z
}
printf("reminder %d",z);

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions