/******************************************************************************
Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
uint8_t zMax(uint16_t A, uint16_t B)
{
uint8_t len = 15; //16-1
uint16_t check = 1<<len;
uint8_t a, b, m, x;
a = (A&check)>>len;
b = (B&check)>>len;
//0000000000000001
m=(a^b)^1;//if m=1: (a == b), check the next bit
//check = check>>m;
A = A<<m;
B = B<<m;
// calculate a and b
a = (A&check)>>len;
b = (B&check)>>len;
//0000000000000010
m=(a^b)^1;//if m=1: (a == b), check the next bit
//check = check>>m;
A = A<<m;
B = B<<m;
// calculate a and b
a = (A&check)>>len;
b = (B&check)>>len;
//0000000000000100
m=(a^b)^1;//if m=1: (a == b), check the next bit
//check = check>>m;
A = A<<m;
B = B<<m;
// calculate a and b
a = (A&check)>>len;
b = (B&check)>>len;
//0000000000001000
m=(a^b)^1;//if m=1: (a == b), check the next bit
//check = check>>m;
A = A<<m;
B = B<<m;
// calculate a and b
a = (A&check)>>len;
b = (B&check)>>len;
//0000000000010000
m=(a^b)^1;//if m=1: (a == b), check the next bit
//check = check>>m;
A = A<<m;
B = B<<m;
// calculate a and b
a = (A&check)>>len;
b = (B&check)>>len;
//0000000000100000
m=(a^b)^1;//if m=1: (a == b), check the next bit
//check = check>>m;
A = A<<m;
B = B<<m;
// calculate a and b
a = (A&check)>>len;
b = (B&check)>>len;
//0000000001000000
m=(a^b)^1;//if m=1: (a == b), check the next bit
//check = check>>m;
A = A<<m;
B = B<<m;
// calculate a and b
a = (A&check)>>len;
b = (B&check)>>len;
//0000000010000000
m=(a^b)^1;//if m=1: (a == b), check the next bit
//check = check>>m;
A = A<<m;
B = B<<m;
// calculate a and b
a = (A&check)>>len;
b = (B&check)>>len;
//0000000100000000
m=(a^b)^1;//if m=1: (a == b), check the next bit
//check = check>>m;
A = A<<m;
B = B<<m;
// calculate a and b
a = (A&check)>>len;
b = (B&check)>>len;
//0000001000000000
m=(a^b)^1;//if m=1: (a == b), check the next bit
//check = check>>m;
A = A<<m;
B = B<<m;
// calculate a and b
a = (A&check)>>len;
b = (B&check)>>len;
//0000010000000000
m=(a^b)^1;//if m=1: (a == b), check the next bit
//check = check>>m;
A = A<<m;
B = B<<m;
// calculate a and b
a = (A&check)>>len;
b = (B&check)>>len;
//0000100000000000
m=(a^b)^1;//if m=1: (a == b), check the next bit
//check = check>>m;
A = A<<m;
B = B<<m;
// calculate a and b
a = (A&check)>>len;
b = (B&check)>>len;
//0001000000000000
m=(a^b)^1;//if m=1: (a == b), check the next bit
//check = check>>m;
A = A<<m;
B = B<<m;
// calculate a and b
a = (A&check)>>len;
b = (B&check)>>len;
//0010000000000000
m=(a^b)^1;//if m=1: (a == b), check the next bit
//check = check>>m;
A = A<<m;
B = B<<m;
// calculate a and b
a = (A&check)>>len;
b = (B&check)>>len;
//0100000000000000
m=(a^b)^1;//if m=1: (a == b), check the next bit
//check = check>>m;
A = A<<m;
B = B<<m;
// calculate a and b
a = (A&check)>>len;
b = (B&check)>>len;
//1000000000000000
x = (a^b)^1;
return ((a&(~b))^1)<<x;
}
uint16_t Max(uint16_t A,uint16_t B)
{
return (A>B) ? A:B;
}
int main(void)
{
puts("!!!Hello World!!!\r\n"); /* prints !!!Hello World!!! */
uint16_t breakc = 0;
for(int A=0;A<0xFFF;A++)
{
for(int B=0;B<0xFFF;B++)
{
if(zMax(A,B)!=Max(A,B))
{
printf("A=%i,B=%i\tMax=%i\r\n",A,B,zMax(A,B));
if(breakc++>=4)
{
printf("\r\n END.");
return 0;
}
}
}
}
printf("\r\n END.");
return 0;
}