How does this print “hello world”?

后端 未结 9 1328
Happy的楠姐
Happy的楠姐 2021-01-29 17:33

I discovered this oddity:

for (long l = 4946144450195624l; l > 0; l >>= 5)
    System.out.print((char) (((l & 31 | 64) % 95) + 32));
9条回答
  •  情歌与酒
    2021-01-29 18:20

    It prints "hello world" for a similar reason this does:

    for (int k=1587463874; k>0; k>>=3)
         System.out.print((char) (100 + Math.pow(2,2*(((k&7^1)-1)>>3 + 1) + (k&7&3)) + 10*((k&7)>>2) + (((k&7)-7)>>3) + 1 - ((-(k&7^5)>>3) + 1)*80));
    

    but for a somewhat different reason than this:

    for (int k=2011378; k>0; k>>=2)
        System.out.print((char) (110 + Math.pow(2,2*(((k^1)-1)>>21 + 1) + (k&3)) - ((k&8192)/8192 + 7.9*(-(k^1964)>>21) - .1*(-((k&35)^35)>>21) + .3*(-((k&120)^120)>>21) + (-((k|7)^7)>>21) + 9.1)*10));
    

提交回复
热议问题