[algogeeks] Re: Symantec ques - Find maximum element without using comparison operators

2011-09-17 Thread siva viknesh
@prasanth  I know this solution...Try giving with constraints
specified ...
only following operations are available...

SHR reg1, op1
ADD reg1, op1
AND reg1, op1
NOT reg1.

On Sep 17, 6:46 pm, prasanth n nprasnt...@gmail.com wrote:
 let a and b be the two numbers

 int temp,result;
 temp=a-b;
 //if temp is -ve,then its MSB will be 1..else it ll be 0..so
 temp=temp  (131);

 //now temp either holds 0(if temp is +ve) or a -ve no(if temp is -ve)

 result=a - temp(a-b);
 //now result contains the required value since a-(a-b)=b
 printf(%d,result);

 On Sat, Sep 17, 2011 at 7:03 PM, sivaviknesh s sivavikne...@gmail.comwrote:









  Two registers A and B. Initial Contents of the registers are unknown.
  Write a program to find MAXINT - The maximum positive unsigned integer
  The instructions available are:
  SHR reg1, op1
  ADD reg1, op1
  AND reg1, op1
  NOT reg1.
  Op1 may represent any number or register.
  (Hint: The Shift operation is a logical shift, not arithmetic shift.)

  ..solution plz .. i tried but unable to arrive

  --
  Regards,
  $iva

   --
  You received this message because you are subscribed to the Google Groups
  Algorithm Geeks group.
  To post to this group, send email to algogeeks@googlegroups.com.
  To unsubscribe from this group, send email to
  algogeeks+unsubscr...@googlegroups.com.
  For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.

 --
 *prasanth*

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Re: Symantec ques - Find maximum element without using comparison operators

2011-09-17 Thread Dave
@Sivaviknesh: I already answered in another thread, but it is short,
so here goes again.

AND A,0 // sets register A to zero
NOT A// complements the bits of A

The result is that register A is filled with 1-bits, giving MAXINT.

Dave

On Sep 17, 8:33 am, sivaviknesh s sivavikne...@gmail.com wrote:
 Two registers A and B. Initial Contents of the registers are unknown.
 Write a program to find MAXINT - The maximum positive unsigned integer
 The instructions available are:
 SHR reg1, op1
 ADD reg1, op1
 AND reg1, op1
 NOT reg1.
 Op1 may represent any number or register.
 (Hint: The Shift operation is a logical shift, not arithmetic shift.)

 ..solution plz .. i tried but unable to arrive

 --
 Regards,
 $iva

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.