ScrapExplorer - gates.c

Home / lab / c / virtual_hardware / mod Lines: 1 | Size: 975 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* SPDX-License-Identifier: GPL-3.0 2 * Virtual hardware 3 * 4 * gates.c 5 * 6 * COPYRIGHT NOTICE 7 * Copyright (C) 2024-2025 0x4248 and contributors 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the license is not changed. 10 * 11 * This software is free and open source. Licensed under the GNU general 12 * public license version 3.0 as published by the Free Software Foundation. 13*/ 14 15#include "lib/libbit.h" 16#include "mod/gates.h" 17 18bit NOT(bit a){ 19 return !(a); 20} 21 22bit NAND(bit a, bit b){ 23 return NOT(a & b); 24} 25 26bit AND(bit a, bit b){ 27 bit ret = NAND(a,b); 28 return NAND(ret, ret); 29} 30 31bit OR(bit a, bit b){ 32 return NAND(NAND(a,a), NAND(b,b)); 33} 34 35bit NOR(bit a, bit b){ 36 return NOT(OR(a, b)); 37} 38 39bit XOR(bit a, bit b){ 40 bit nand1 = NAND(a, b); 41 bit nand2 = NAND(a, nand1); 42 bit nand3 = NAND(b, nand1); 43 return NAND(nand2, nand3); 44} 45 46bit XNOR(bit a, bit b){ 47 return NOT(XOR(a, b)); 48} 49
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.