3/14 plz print code so i can compare

1 byte === 8 bit
@coderockstar00502,

 8th-bit             1st-bit
 [bit-7]             [bit-0]
  |                    |
  0  0  0  0  0  0  0  0   <<== This 1 byte, consisting of 8-Bits
 128 64 32 16 8  4  2  1  <<=Decimal Value if bit is set

 [      B i n a r y     ]     [ D e c i m a l ]
  0  0  0  0  0  0  0  0  <<== 0
  0  0  0  0  0  0  0  1  <<== 1
  0  0  0  0  0  0  1  0  <<== 2
  0  0  0  0  0  0  1  1  <<== 2 + 1 = 3
  0  0  0  0  0  1  0  0  <<== 4
  0  0  0  0  0  1  0  1  <<== 1 + 4 =  5
  0  1  0  0  1  0  1  0  <<== 2 + 8 + 64 == 74

= https://www.cs.umd.edu/class/sum2003/cmsc311/Notes/Data/bitBytes.html
= https://en.wikipedia.org/wiki/Units_of_information
= https://en.wikipedia.org/wiki/Nibble

5 Likes

@leonhard_wettengmx_n Would be great if you can explain this even more :wink:

I would love to fully grasp this, I don’t follow the last line where values are added together.
Thanks

1 Like

It’s the same system as you are used to, except that there are two symbols instead of ten.

In base 10 the digit positions say what power of 10 (1, 10, 100, 1000 and so on) is being counted (there can be 0 up to 9 of each such power of 10)

In base 2 the digit positions say what power of 2 (1, 2, 4, 8, 16 and so on) is being counted (there can be either 0 or 1 of each such power of 2)

@ionatan Yeah did a bit of reading on wiki and going further in lessons it becomes a lot more clear. Very interesting I must say, but can get pretty complex as well.
Thanks

@scriptmaster83175,
Updated
= 3/14 plz print code so i can compare

1 Like

@leonhard_wettengmx_n thanks!

one = 0b1 two = 0b10 three = 0b11 four = 0b100 five = 0b101 six = 0b110 seven = 0b111 eight = 0b1000 nine = 0b1001 ten = 0b1010 eleven = 0b1011 twelve = 0b1100

3 Likes

@wolvesandrainbows,

Please re-edit your Post

  • leave one blank-line above of your code
  • select your code in the Post
  • then =click= on the </>-symbol-of-this-editor

Your code will then be in a pre-code state
and you will be able to make/present the proper indentations.

or even better use
= http://discuss.codecademy.com/t/using-backticks-to-format-your-code/3697

If you still need help, this is how I learned Binary:
First create the table below:
1024 512 256 128 64 32 16 8 4 2 1

Next see what is the biggest number that can you can subtract from what you want to covert to binary. For my first example I will use 8.

1024 512 256 128 64 32 16 8 4 2 1 

The number 8 can go into 8.

Put a 1 under the 8 and zeros under the rest of the numbers to the right like this:
1024 512 256 128 64 32 16 8 4 2 1 
                          1 0 0 0

so the binary for 8 is 0b1000.

Lets try a bigger number that doesn't go in evenly: 12
1024 512 256 128 64 32 16 8 4 2 1 

Subtract 12 by the biggest applicable number on the table:
(use 8)
12-8 = 4 so your chart so far should look like : 
1024 512 256 128 64 32 16 8 4 2 1 
                          1
Next what is the next biggest number you can subtract from 4 (your remaining number that you got from 12-8)? (use 4 because 4 can evenly go into 4)
1024 512 256 128 64 32 16 8 4 2 1 
                          1 1

Now that you have subtracted 12 by 8 and 4 there is nothing left so you fill in the zeros for the rest of the numbers in the table to the right:
1024 512 256 128 64 32 16 8 4 2 1
                          1 1 0 0 

so the binary for 12 is 0b1100. 

If you need anymore help or something doesn't make since feel free to reply to this.

Ok, I tried to reformat this. I hope this works…

2 Likes

Thank you SO much for the slow breakdown of the information rarely I find a post like this that I really understand! Keep up the good work! (thumbsup)

you have to read from right to left. First off, look at the pattern of what you are doing.
one = 0b1 = 1 (the right most bit is the “1’s” bit
two = 0b10 = 2 if the right most bit is 0 it is always an even number. The 2’s bit is on
three = 0b11 = 3 is an odd number. the 2’s bit is on and the 1’s bit is on therefore, 3 is correct
four = 0b11 = 3. 4 would be 0b100. 3rd bit is the 4’s bit. See it unfolding? (1000 would be 8 and 10000 would be 16) what would be 32?
five = 0b1100 = 12 (8,4,0,0 to think is base 10 and read right to left. 8’s bit on, 4’s bit on 2’s bit off 1’s bit off. It is an even number, of course
six = 0b11000 = 16 + 8 = 24
seven = 0b110000 = 32 + 16 = 48
eight = 0b1100000 = 64 + 32 = 96
nine = 0b11000000 = 128 + 64 = 192
ten = 0b1100000000 = 256 + 128 = 384
eleven = 0b1100000000000 = You get the idea

Thanks for this method. I really plan on using this in the future :smiley:

I’m glad I could help!

one = 0b1
two = 0b10
three = 0b11
four = 0b100
five = 0b101
six = 0b110
seven =0b111
eight =0b1000
nine = 0b1001
ten = 0b1010
eleven =0b1011
twelve =0b1100

Thank you. This helped a bunch.

Hey guys, if anyone has trouble understanding how to count in binary. I recommend watching this video. It is a short lesson and explained EXTREMELY well.

Hope this helps guys! :smiley:

Correct answer:
one = 0b1
two = 0b10
three = 0b11
four = 0b100
five = 0b101
six = 0b110
seven = 0b111
eight = 0b1000
nine = 0b1001
ten = 0b1010
eleven = 0b1011
twelve = 0b1100

1 Like

Thanks, it was hard but i understand)

Formatting bit this way made me completely understand what to do. Thanks!!

what about for a number like 11 or 13?

@burnoutbiograd

The decimal number 11
1024 512 256 128 64 32 16 8 4 2 1
                          1 0 1 1 Binary
The decimal number 13
1024 512 256 128 64 32 16 8 4 2 1
                          1 1 0 1 Binary