Anonymous user
Four bit adder: Difference between revisions
Fixed up description more (wording only)
(→{{header|C}}: Try to satisfy both the language expression interest and the task requirements.) |
(Fixed up description more (wording only)) |
||
Line 1:
{{task}}
The aim of this task is to "''simulate''" a four
▲be "imitated" by the use of the bitwise operators of your language. If there is no a ''bit type'' in your language, to be sure that the ''not'' does not "invert" all the other bits of the basic type (e.g. a byte) we are not interested in, you can use an extra ''and'' with the constant 1.
Instead of optimizing and reducing the number of
Schematics of these "constructive blocks" are
[[File:xor.png|thumb|Xor gate done with ands, ors and nots]]
[[File:halfadder.png|thumb|A half adder]]
[[File:fulladder.png|thumb|A full adder]]
[[File:4bitsadder.png|thumb|A 4-
Solutions should try to be as descriptive as possible, making it as easy as possible to identify "connections" between higher-order "blocks". It is not mandatory to replicate the syntax of higher-order blocks in the atomic "gate" blocks, i.e. basic "gate" operations can be performed as usual bitwise operations, or they can be "wrapped" in a ''block'' in order to expose the same syntax of higher-order blocks, at implementers' choice.
To test the implementation, show the sum of two four-
=={{header|C}}==
Line 31 ⟶ 30:
#define NOT(X) (~(X)&1)
/* a shortcut to "implement" a XOR using only NOT, AND and OR gates
task requirements constrain */
#define XOR(X,Y) ((NOT(X)&(Y)) | ((X)&NOT(Y)))
void halfadder(IN a, IN b, OUT s, OUT c)
|