Creating a 4 bit multiplier with only two methods (final programming contest task at our university)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bigbabo
    New Member
    • Mar 2022
    • 2

    Creating a 4 bit multiplier with only two methods (final programming contest task at our university)

    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)
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 656

    #2
    Since
    You must not use loops, conditions, other variables, etc.
    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.
    Use the truth table to derive the output expressions and implement the sum and carry using operators.

    Truth table https://en.wikipedia.org/wiki/Adder_(electronics)

    A is the bit of the first number. B is the respective bit of the second number. C is the carry bit.

    Sum = C XOR (A XOR B)
    Carry = AB + BC + AC

    The above expression can be obtained after simplification (a method like K-map https://en.wikipedia.org/wiki/Karnaugh_map
    can be used).

    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.
    Use bitwise AND.

    Comment

    Working...