Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- aight, so bits have different powers based on where they're positioned, just like our regular digit system: the 1 in 1000 is a hundred times as valuable as the 1 in 10
- the binary system assigns bits powers starting from 1, and from there on it's the last bit multiplied by two
- 128 64 32 16 8 4 2 1 - values of bits in a "byte"
- 1 0 0 1 0 1 0 1 - the number stored in this byte
- now, we'll simply add up the numbers above each high (1) bit: 128+16+4+1 = 149
- naturally, this process works the other way around as well... say we have the number 167.
- we'll start by finding the biggest power we can subtract from our number so it doesn't become negative. Right now it's 128, so we do 167-128 and get 39. Now we put a 1 below 128.
- next, we can't subtract 64, so we put a 0 below that. 32 is fine, giving us 7 and a 1 below 32.
- next number we can subtract is 4, putting 0 below 16 and 8, and 1 below 4... now we are only left with 3, putting a 1 below 2 and 1 as well
- 128 64 32 16 8 4 2 1 - values of bits in a "byte"
- 1 0 1 0 0 1 1 1 - the calculated binary number
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement