0
Create function to add numbers of a given base
I want to create a function to that gets a base and some numbers and returns sum of the numbers in the given base. For example i want to add 1111, 1001, 1101, 1100 in base 2 and get the answer : 110001 I tried to iterate on each numbers digit and get the sum but i couldnt do it right. Could anyone help me?
2 Antworten
0
Whats an example input/output
Yasaman Shokri if you want to do it from scratch:
- make sure each base 2 number is a string
- flip the string
- use the index values as values for the base
(index 0, the first value, will be 2 ^ 0. inex 1 will be 2 ^ 1 and so on)
- add it up and keep track
- do this for every single one
- add all those together
- then either reverse the process, or use bin() function to convert sum back to base 2
0
something like this should be helpful. I guess
https://code.sololearn.com/c23cDV18bmMA