# I tought myself how to read binary #361

Jmzd8 (edited )

if you dont want me explaining it dont open this

so each digit will have its corresponding number that increases by itself every digit, so the first digit is 1 the second digit is 2 the third digit is 4 etc etc. calling these numbers "BN"

so kinda like this:

0 0 0 0 0 0 (binary)

32 16 8 4 2 1 (BNs)

so say you want to get the decimal number of the binary number 011010. you get the BNs corresponding with the places where there is a 1 and add them all together. like this:

0 1 1 0 1 0

16+8+4 = 26

im not really sure if you can do this with numbers higher than 63 (aka more than 6 binary digits)

taswelll (edited )

this is right! this is how binary to decimal conversion works. the BNs are the the powers of two: each digit is the previous increased by itself => each digit is the previous multiplied by 2 => nth digit is 2 to the nth power.

positional base for a given B works the same way if you change "add all the powers of two where there is a one" to "add all the powers of K multiplied by the corresponding digit" (these are equivalent if K is 2; multiplying something by 0 is 0)

say you want to get the decimal number of the octal number 5756. let's get the powers that we need:

• 83 = 512
• 82 = 64
• 81 = 8
• 80 = 1

and 5*512 + 7*64 + 5*8 + 6*1 = 3054. this will work for every octal(/binary) number!

viba

beenary

caesar (edited )

there's a faster algorithm

if it's all zeroes the number is 0

ignore all digits up to and including the first 1 (left-to-right)

when you see a zero, 2n

when you see a one, 2n + 1

so 00000101:

n = 1 (1)01

n = 2 1(0)1

n = 4 + 1 10(1)

n = 5

big brother (bureaucrat)
this post never existed.
taswelll (edited )

yes! ax5 + bx4 + cx3 + dx2 + ex + f = f + x(e + x(d + x(c + x(b + ax))))

taswelll

""Horner's method""

caesar

oh cool, this is related to synthetic division (the best kind of polynomial division). but i discovered this algorithm myself

Jmzd8 (edited )

this is a better way of explaining it thanks

taswelll

have some powers of two, as a treat: 4294967296 2147483648 1073741824 536870912 268435456 134217728 67108864 33554432 16777216 8388608 4194304 2097152 1048576 524288 262144 131072 65536 32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1

amby

fun fact: this algorithm can be expanded to parse arbitrary bases (so long as you have a base-N digit to integer conversion)

start on the most significant digit
multiply by the base
move to the next digit
repeat until you run out of digits

caesar

indeed! bn + d

taswelll

beaned

amby

beaned.......

i first saw that algorithm used in jonesforth btw

Jmzd8

baked beans

ubq323 (bureaucrat)

yes, in the same way that in decimal, each digit from the right corresponds to the next highest power of ten, in binary each digit from the right corresponds to the next highest power of two. this is true of any base.

mb

synthetic division (the best kind of polynomial division).

but it's opaque - hard to see what it's actually doing at each step

caesar

long polynomial division is extremely complicated, i'd say it's more opaque for that reason

taswelll

it might be a bit more opaque but it's useful

taswelll

(i like useful)

caesar

divide 3x³ + 2x² + 4x + 7 by x² + 7x - 2 using long division (hard, extremely complicated. borderline impossible. useless)

do the same division using synthetic division (easy, not at all inconvenient, extremely simple. useful) (i also like useful)

gollark

REAL programmers just make computers do all division tasks.

mb

you can synthetically divide by polynomials with degrees higher than 1?

caesar

of course! it's all explained on the Wikipedia page for synthetic division

hopefully apioforum uses markdown so that link works

taswelll

apioforum uses markdown!

caesar

# yay! c: bzzzzzzzzzt

mb

done

``````               3x   - 19
--------------------------
x^2 + 7x - 2 ) 3x^3 +  2x^2 +   4x +  7
3x^3 + 21x^2 -   6x
-------------------
-19x^2 +  10x +  7
-19x^2 - 133x + 38
------------------
143x - 31
``````
Incoherent (edited )

ok but consider

``````       3    2     4     7
2 |            6   -38
-7   |    -21   133
--------------------
3  -19 | 143   -31

3x - 19 R 143x -31
``````