Created
January 20, 2023 11:57
-
-
Save angeloped/90dfacfd7aab0b541acf29f66055c791 to your computer and use it in GitHub Desktop.
Boolean Comparing Operation | MHIP kernel component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
// Boolean Comparing Operation | MHIP kernel component | |
// Bryan Pedrosa | |
// 1/20/2023 | |
// modes: | |
//[0x0]BOOL_EQ - equal | |
//[0x1]BOOL_LT - less than | |
//[0x2]BOOL_GT - greater than | |
//[0x3]BOOL_LE - less than equal | |
//[0x4]BOOL_GE - greater than equal | |
int BOOL_OP(int mode, int size, int A[], int B[]){ | |
int status = 0x0; // EQ | |
for(int i=0; i<size; i++){ | |
if( A[i] < B[i] ){ | |
status = 0x1; // LT | |
break; | |
} | |
if( A[i] > B[i] ){ | |
status = 0x2; // GT | |
break; | |
} | |
} | |
if(mode < 0x3){ | |
return status == mode; // EQ/LT/GT combined (0x0/0x1/0x2) | |
}else{ | |
return (status==0x0) | (status==mode-2); // LE/GE combined (0x3/0x4) | |
} | |
} | |
int main(){ | |
int A[3] = {0,0,1}; | |
int B[3] = {0,1,1}; | |
printf("%d\n", BOOL_OP(0x3, 3, A, B) ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Boolean Comparing Operation | MHIP kernel component | |
# Bryan Pedrosa | |
# 1/20/2023 | |
# modes: | |
#[0x0]BOOL_EQ - equal | |
#[0x1]BOOL_LT - less than | |
#[0x2]BOOL_GT - greater than | |
#[0x3]BOOL_LE - less than equal | |
#[0x4]BOOL_GE - greater than equal | |
def BOOL_OP(mode, size, A, B): | |
status = 0x0 # EQ | |
for i in range(size): | |
if A[i] < B[i]: | |
status = 0x1 # LT | |
break | |
if A[i] > B[i]: | |
status = 0x2 # GT | |
break | |
if mode < 0x3: | |
return status == mode # EQ/LT/GT combined (0x0/0x1/0x2) | |
else: | |
return (status==0x0) | (status==mode-2) # LE/GE combined (0x3/0x4) | |
A = [0,0,1] | |
B = [0,1,1] | |
print(BOOL_OP(0x3, 3, A, B)) | |
print(BOOL_OP(0x3, 3, "001", "011")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment