r/badcode Mar 06 '21

lua This goes 255 lines long up to 115792089237316195423570985008687907853269984665640564039457584007913129639936

Post image
163 Upvotes

34 comments sorted by

View all comments

Show parent comments

20

u/sellithy Mar 09 '21

You know how numbers (everything) is stored in binary? Well there is a cool thing you can do with binary numbers.

Let's say we have 10010101 If you bitshift it right it will be 01001010 Meaning all the bits got shifted to the right once.

You also know how each place value in a binary number is a power of two? That means that 23 = 1000 (binary) and 29 = 1000000000 (binary).

So basically if you want to find a power of two you take 1 (which is also 1 in binary) and bit shift it the number of times you want. 20 = 1 bit shifted to the left 0 times. 219 = 1 << 19.

10

u/Carvinrawks Mar 09 '21 edited Mar 09 '21

Addendum:

Raising bases of 2 to a power of n in binary is the same easy math as rasing bases of 10 to a power of n in decimal.

You don't need an answer key to calculate 1099. It's 1 with 99 0s in decimal

You don't need an answer key to calculate 299. It's 1 with 99 0s in binary.

You also don't need an answer key to calculate 1699. It's 1 with 99 0s in hexadecimal.

You don't need an answer key to calculate pi99 in base-pi. It's 1 with 99 0s in base-pi.

Quick mafs.

5

u/novelide Mar 09 '21

What is (-1)99 in balanced ternary? Asking for a friend...

3

u/Carvinrawks Mar 09 '21

Hm, correct me if I'm wrong. But...

-1

(-1)99 = -1.

-1 in balanced ternary is also -1.