mirror of
https://github.com/ehw-fit/ariths-gen.git
synced 2025-04-22 06:41:22 +01:00
27 lines
535 B
C
27 lines
535 B
C
#include <stdio.h>
|
|
#include <stdint.h>
|
|
|
|
uint8_t xor_gate(uint8_t _a, uint8_t _b){
|
|
return ((_a >> 0) & 0x01) ^ ((_b >> 0) & 0x01);
|
|
}
|
|
|
|
uint8_t and_gate(uint8_t _a, uint8_t _b){
|
|
return ((_a >> 0) & 0x01) & ((_b >> 0) & 0x01);
|
|
}
|
|
|
|
uint8_t h_ha(uint8_t a, uint8_t b){
|
|
uint8_t out = 0;
|
|
out |= (xor_gate(a, b) & 0x01) << 0;
|
|
out |= (and_gate(a, b) & 0x01) << 1;
|
|
return out;
|
|
}
|
|
|
|
#include <assert.h>
|
|
int main(){
|
|
for (int i = 0; i < 2; i++){
|
|
for (int j = 0; j < 2; j++){
|
|
assert((i + j) == h_ha(i,j));
|
|
}
|
|
}
|
|
return 0;
|
|
} |