+ Reply to Thread
Results 1 to 6 of 6

How to convert binary to decimal & vice versa?

  1. #1
    Registered User
    Join Date
    08-02-2005
    Posts
    6

    How to convert binary to decimal & vice versa?

    hi!

    i wonder if anyone has ever tried to convert binary no. to decimal & vice versa in excel?

    Thanks!

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996
    Like this....

    A1: 125
    B1: =DEC2BIN(A1) <---Results in 1111101

    A2: 1111101
    B2: =BIN2DEC(A2) <--Results in 125

    Note: If those functions are not available, and return the #NAME? error:
    Tools>Addins...Select Analysist Toolpak

    Does that help?

    Ron

  3. #3
    Registered User
    Join Date
    08-02-2005
    Posts
    6
    hey thanks so much!

    yup sure enough, i got the #Name error and had to add the additional feature frm the EXCEL installer.

    if anyone else has another solution, do share it with me! thanks again!

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,827
    Converting from binary to decimal is a simple "sumproduct."

    (Working from right to left) 1101=1*2^0+0*2^1+1*2^2+1*2^3=13

    There are a few different algorithms for converting decimal to binary. Involves dividing repeatedly by 2 and noting the remainder (or noting if the number is even, or however you want to look at it). These algorithms are described in several places on the net. Put "convert decimal to binary" in your favorite search engine.

  5. #5
    Harlan Grove
    Guest

    Re: How to convert binary to decimal & vice versa?

    hmmm wrote...
    >i wonder if anyone has ever tried to convert binary no. to decimal &
    >vice versa in excel?


    If you just want to go up to 2^16-1, one purely built-in way to convert
    the decimal number x to binary is

    =MOD(INT(x/2^15),2)&MOD(INT(x/2^14),2)&MOD(INT(x/2^13),2)&MOD(INT(x/2^12),2)
    &MOD(INT(x/2^11),2)&MOD(INT(x/2^10),2)&MOD(INT(x/2^9),2)&MOD(INT(x/2^8),2)
    &MOD(INT(x/2^7),2)&MOD(INT(x/2^6),2)&MOD(INT(x/2^5),2)&MOD(INT(x/2^4),2)
    &MOD(INT(x/2^3),2)&MOD(INT(x/2^2),2)&MOD(INT(x/2),2)&MOD(x,2)

    And to convert the binary number b to decimal,

    =SUMPRODUCT(MID(b,ROW(INDIRECT("1:"&LEN(b))),1)
    *2^(LEN(b)-ROW(INDIRECT("1:"&LEN(b)))))


  6. #6
    Jerry W. Lewis
    Guest

    Re: How to convert binary to decimal & vice versa?

    And for integers beyond the limit of DEC2BIN, see

    http://groups-beta.google.com/group/...08d54fb185312e

    Jerry

    Harlan Grove wrote:

    > hmmm wrote...
    >
    >>i wonder if anyone has ever tried to convert binary no. to decimal &
    >>vice versa in excel?
    >>

    >
    > If you just want to go up to 2^16-1, one purely built-in way to convert
    > the decimal number x to binary is
    >
    > =MOD(INT(x/2^15),2)&MOD(INT(x/2^14),2)&MOD(INT(x/2^13),2)&MOD(INT(x/2^12),2)
    > &MOD(INT(x/2^11),2)&MOD(INT(x/2^10),2)&MOD(INT(x/2^9),2)&MOD(INT(x/2^8),2)
    > &MOD(INT(x/2^7),2)&MOD(INT(x/2^6),2)&MOD(INT(x/2^5),2)&MOD(INT(x/2^4),2)
    > &MOD(INT(x/2^3),2)&MOD(INT(x/2^2),2)&MOD(INT(x/2),2)&MOD(x,2)
    >
    > And to convert the binary number b to decimal,
    >
    > =SUMPRODUCT(MID(b,ROW(INDIRECT("1:"&LEN(b))),1)
    > *2^(LEN(b)-ROW(INDIRECT("1:"&LEN(b)))))



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1