Some numbers do not match on 81 (Bit Count)

Back to Problem Solutions forum

astjoemd     2016-02-04 00:01:09

Hello! So I've tried solving problem #81. This was given as the input:

60
646461 -17925640 -1973567 -1439 -4 -49831055 16372286 -1331 -56548956 -7105407 -186429 1316137559 6325 12217973 -1427670839 -1278223059 -67974 -123132 860105 -195744055 1280 -108318104 -18740 -140143023 -12 109009 -88505044 1176 -40 2532 706315360 4065 -1146479 -9 111 -148211580 797 53 85013 15855 1454 -31801575 -1495583143 1618544267 -19086965 18 -551809585 -862735095 -195781 70 13 -975 -876650 -854655 -3 4 42 -266 1165109 15233

My answer was:

13 26 19 25 32 18 15 27 16 17 23 17 7 15 18 21 27 23 12 17 2 19 27 18 31 9 19 4 31 6 10 8 19 31 6 18 6 4 7 12 7 20 18 13 19 2 19 15 22 3 3 25 24 21 31 1 3 30 11 7

And the expected one was:

13 23 19 25 30 18 15 27 14 17 23 17 7 15 18 21 26 21 12 17 2 16 25 18 29 9 17 4 28 6 10 8 19 31 6 16 6 4 7 12 7 20 18 13 19 2 19 15 22 3 3 25 23 21 31 1 3 29 11 7

I've solved it almost completely — the problem is, some negative numbers do not much, while some do, and I can't figure out the correlation. This issue only seems to arise among negative numbers.

I have no clue what I'm doing wrong. Has anyone faced this problem as well? Any help would be appreciated!

Quandray     2016-02-04 07:26:21
User avatar

Hi,

For -17925640 your answer is 26 but the correct answer is 23.

+17925640 in binary is 00000001000100011000011000001000, but

-17925640 in binary is 11111110111011100111100111111000

https://en.wikipedia.org/wiki/Two's_complement may help

astjoemd     2016-02-04 22:12:38

Awesome! I did some further research based off that link and found the operators I needed. It has accepted my answer now. Thanks a lot!

Please login and solve 5 problems to be able to post at forum