Skip to content

Instantly share code, notes, and snippets.

@Havvy
Last active October 7, 2016 11:26
Show Gist options
  • Save Havvy/3766c12e8552cafe693f7bf990f688ff to your computer and use it in GitHub Desktop.
Save Havvy/3766c12e8552cafe693f7bf990f688ff to your computer and use it in GitHub Desktop.
┌─         ─┐
│ 1 0 0 0 ⋯│
│ 0 1 0 0 ⋯│
│ 0 0 1 0 ⋯│
│ 0 1 0 1 ⋯│
│ 0 0 0 0 ⋯│
│ 0 0 1 1 ⋯│
│ 0 0 1 1 ⋯│
│ 0 0 0 1 ⋯│
│ 0 0 0 1 ⋯│
│ 0 0 0 1 ⋯│
│ 0 0 0 0 ⋯│
|  ⋮ ⋮ ⋮ ⋮ ⋱ │
└─         ─┘

Example: Let's turn 762 into binary.

┌─         ─┐┌─ ─┐
│ 1 0 0 0 ⋯││ 2 │
│ 0 1 0 0 ⋯││ 6 │
│ 0 0 1 0 ⋯││ 7 │
│ 0 1 0 1 ⋯││ 0 │
│ 0 0 0 0 ⋯││ 0 │
│ 0 0 1 1 ⋯││ 0 │
│ 0 0 1 1 ⋯││ 0 │
│ 0 0 0 1 ⋯││ 0 │
│ 0 0 0 1 ⋯││ 0 │
│ 0 0 0 1 ⋯││ 0 │
│ 0 0 0 0 ⋯││ 0 │
|  ⋮ ⋮ ⋮ ⋮ ⋱ ││ ⋮ │
└─         ─┘└─ ─┘

= (Rotated) [2 6 7 6 0 7 7 0 ⋯ ]
= 2*2^0 + 6*2^1 + 7*2^2 + 6*2^3 + 0*2^4 + 7*2^5 + 7*2^6

But that still leaves the scalars in decimal. Let's convert those into binary. We'll leave the 2 and the exponents as decimal.

= 10*2^0 + 110*2^1 + 111*2^2 + 110*2^3 + 0*2^4 + 111*2^5 + 111*2^6

But that still leaves the values non-normalized. We can normalize by moving higher digits into upper bases for each power.

= 0*2^0 + (1+110)*2^1 + 111*2^2 + 110*2^3 + 0*2^4 + 111*2^5 + 111*2^6
= 0*2^0 + 1*2^1 + (11+111)*2^2 + 110*2^3 + 0*2^4 + 111*2^5 + 111*2^6
= 0*2^0 + 1*2^1 + 0*2^2 + (101+110)*2^3 + 0*2^4 + 111*2^5 + 111*2^6
= 0*2^0 + 1*2^1 + 0*2^2 + 1*2^3 + (101+0)*2^4 + 111*2^5 + 111*2^6
= 0*2^0 + 1*2^1 + 0*2^2 + 1*2^3 + 1*2^4 + (10+111)*2^5 + 111*2^6
= 0*2^0 + 1*2^1 + 0*2^2 + 1*2^3 + 1*2^4 + 1*2^5 + (101+111)*2^6
= 0*2^0 + 1*2^1 + 0*2^2 + 1*2^3 + 1*2^4 + 1*2^5 + 0*2^6 + 110*2^7
= 0*2^0 + 1*2^1 + 0*2^2 + 1*2^3 + 1*2^4 + 1*2^5 + 0*2^6 + 0*2^7 + 1*2^8 + 1*2^9
= 1100111010
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment