How to compute the maximun(max) of two integers using bitwise operators in C

1 Answer

0 votes
#include <stdio.h>

int main(void) {
    int x = 8290, y = 1000;              

    int result = x ^ ((x ^ y) & -(x < y)); // max(x, y)
  
    printf("%d\n", result);
      
    return 0;
}
  
  
  
  
/*
run:

8290

*/

 



answered Apr 9, 2024 by avibootz

Related questions

1 answer 214 views
1 answer 196 views
2 answers 282 views
3 answers 370 views
...