logotransparent.png

Legion of Learners

www.lol-101.com

  • Home

  • Classrooms

  • Courses

  • About Us

    • Executive Team
    • Board Members
  • Resources

  • More

    Use tab to navigate through the menu items.
    To see this working, head to your live site.
    • Categories
    • All Posts
    • My Posts
    sfolax6776
    Jul 10, 2018
      ·  Edited: Oct 14, 2019

    2.11 Conversion between binary and decimal numbers

    in Introduction to Java

    A. Introduction

    Turn a binary number into decimal is easy: just multiply each digit with its place value and add up. e.g. 1101 = 1*2^3 + 1*2^2 + 0*2^1 + 1*2^0 = 8+4+1=13

    B. Two ways to turn decimal into binary:

    1. Divide the number by 2 until the quotient is 0, then write down all the remainder backwards.


    2. Descending power of 2 and subtract:

    1. Find the largest power of 2 that can fit in the decimal number x, let that be n. If x>2^n, note down 1 (from highest to lowest, i.e. left to right) otherwise note down 0.

    2. x = x - 2^n

    3. n=n-1 if n>=0, go back to step 1; otherwise done.

    C. Try:

    • Convert the following binary numbers into decimal numbers:

    1011, 1101, 1111, 10001, 11001, 1100010011, 1000111011.

    • Convert the following decimal numbers into binary numbers:

    123, 789, 9021, 8762, -1000000, 0.5

    3 comments
    0
    mr.ricklu
    Jul 14, 2018


    wangernestrdragon
    Jul 15, 2018

    1)2^3+2^1+2^0=11

    2)2^3+2^2+2^0=13

    3)2^3+2^2+2^1+2^0=14

    4)2^4+2^0=17

    5)2^4+2^3+2^0=25

    6)2^9+2^8+2^4+2^1+2^0=787

    7)2^9+2^5+2^4+2^3+2^1+2^0=571

    8)111101

    9)1100010101

    10)10001100111101

    11)10001000111010

    12)-11110100001001000000

    13)0.1

    0
    tian
    Jul 15, 2018

    11, 13, 15, 17, 25, 787, 571


    1111011, 1100010101, 10001100111101, 10001000111010, -11110100001001000000, 0.1

    0
    3 comments

    Questions? Email us at legionoflearners@gmail.com or join our WeChat group!

    • lol-101dotcom

    ©2020 Legion of Learners