I saw this task at a programming competition at our university and since then I can't get rid of it.
I somehow can't figure out which logical conclusion to make.
We have given two methods:
Once a 4 bit Adder, where I pass two 4 bit numbers as a String. As return value I get the addition and a carry bit in a string array, where in the first string are the 4 bits of the addition and in the second string the carry bit.
In addition we have a 4 bit identity method A 4 bit identity simply means that I pass 4 bits to this method and another bit, if the other bit is 0 the method returns 0000 as a String, but if the bit is 1,the method returns the 4 bits, which I gave the method as a String.
You must not use loops, conditions, other variables, etc. Only the two methods.
The adder method can only be passed two strings that are 4 bits long and as a result, as mentioned, you get in one string the 4 bits of the addition and in another string the carry bit!
And with the identity method you also pass two strings, once a string that must be 4 bits long and another string that is either 1 or 0, if it is 1 you get the passed string back, otherwise 0000.
I know that when I add a number to itself, I create a left shift.
But still I can't get the result....
(As result must come out 8 bits, for this we have given 8 strings, where we can insert the 8 bits one by one).
I don“t now how we could solve this task.
(I dont need the code,I would just like to know what the procedure is)
I somehow can't figure out which logical conclusion to make.
We have given two methods:
Once a 4 bit Adder, where I pass two 4 bit numbers as a String. As return value I get the addition and a carry bit in a string array, where in the first string are the 4 bits of the addition and in the second string the carry bit.
In addition we have a 4 bit identity method A 4 bit identity simply means that I pass 4 bits to this method and another bit, if the other bit is 0 the method returns 0000 as a String, but if the bit is 1,the method returns the 4 bits, which I gave the method as a String.
You must not use loops, conditions, other variables, etc. Only the two methods.
The adder method can only be passed two strings that are 4 bits long and as a result, as mentioned, you get in one string the 4 bits of the addition and in another string the carry bit!
And with the identity method you also pass two strings, once a string that must be 4 bits long and another string that is either 1 or 0, if it is 1 you get the passed string back, otherwise 0000.
I know that when I add a number to itself, I create a left shift.
But still I can't get the result....
(As result must come out 8 bits, for this we have given 8 strings, where we can insert the 8 bits one by one).
I don“t now how we could solve this task.
(I dont need the code,I would just like to know what the procedure is)
Comment