Why didn't the complement's formula work?

好久不见. 提交于 2019-12-25 04:42:43

问题


I have just learnt that to get the formula to find the 1st Complement is

    -x = 2^n - x - 1

I have managed to apply it on a binary case:

     -00001100 (base 2) = 2^8 - 12 - 1 
                        = 243
                        = 11110011 (1s)

However, when I try to apply the same formula to a base 5 number,

     -1042 (base 4) = 5^4 - 1042 - 1
                    = 625 - 1042 - 1
                    = - 400 (which is not the answer)

Can some one help me out here? Thanks


回答1:


you cannot calculate any formula with numbers in 2 different bases, you have to use their decimal representation (or an other representation you can handle)

I'll give it a try in dec:

1042 (base 5) = 1* 5^3 + 4* 5^1 + 2 = 125 + 20 + 2 = 147 dec
5^4 - 147 - 1 = 477 dec
477 = 3* 5^3 + 4* 5^2 + 2 = 3402 (base 5)

in base 5:

5^4 - 1042 - 1 = 10000 - 1043 = 3402


来源:https://stackoverflow.com/questions/28117444/why-didnt-the-complements-formula-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!