I like to golf in
dc, but I'm sometimes frustrated because
dc doesn't have bitwise operations.
Provide four named functions which implement the equivalent of the c bitwise operations
^ (bitwise AND, OR, NOT and XOR). Each function will take two operands (
~ takes only one) which are at least 32-bit unsigned integers. Each function will return an unsigned integer of the same bit-width as the operands.
You may only use operations that are supported by
dc. These are:
/Arithmetic addition, subtraction, multiplication and division
~modulo (or divmod if your language supports it)
<standard equality/inequality operators
<<bit shift operators.
dcdoesn't have these, but since they are trivially implemented in terms of division/multiplication by powers of 2, then I will allow these.
Control structures in
dc my be clumsily built using (recursive) macros and (in)equality operations. You may use whatever built-in control structures your language has.
You may also use logical operators
!, even though these aren't directly available in
You must not use the bitwise operators
^ or any functions that trivially implement them.
In addition you must not use built-in base-conversion-of-string operators or functions.
Please also consider providing a test program or online compiler snippet (not included in the golf score) to help verify your answer.