+ Reply to Thread
Results 1 to 10 of 10

#Num Error while converting nos above 512 into BINARY

  1. #1
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    #Num Error while converting nos above 512 into BINARY

    Dear Forum,

    I am getting a #Num Error while converting nos above 512 into BINARY..

    CAn someone please suggest an option for the same?
    Last edited by e4excel; 06-22-2010 at 02:04 AM.

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: #Num Error while converting nos above 512 into BINARY

    You would probably want to use a UDF ... a single cell native function would be relatively limited in scope given significant digit limitation.

    With a UDF you need simply iterate (down) from 2^n to 2^0 and test to see if the iterated value (2^x) is <= remaining value to be apportioned appending the binary string with 1/0 as appropriate.

    There are no doubt better examples but in basic terms (ignoring sign)

    Please Login or Register  to view this content.
    edit: I'm pretty sure shg will have posted something clever previously if you search the board.
    Last edited by DonkeyOte; 06-16-2010 at 10:41 AM. Reason: typo in narrative (UDF unchanged)

  3. #3
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: #Num Error while converting nos above 512 into BINARY

    How high do you need to go? You can use a workaround like this for 512 to 262143

    =DEC2BIN(INT(A2/512))&DEC2BIN(MOD(A2,512),9)
    Last edited by daddylonglegs; 06-16-2010 at 11:00 AM.
    Audere est facere

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: #Num Error while converting nos above 512 into BINARY

    clever swine....

  5. #5
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: #Num Error while converting nos above 512 into BINARY

    That's one of the first tricks I learnt at another website that dare not mention it's name.....

    You can amend to avoid leading zeroes when A2 < 512

    =RIGHT(DEC2BIN(INT(A2/512))&DEC2BIN(MOD(A2,512),9),LOG(A2,2)+1)

  6. #6
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: #Num Error while converting nos above 512 into BINARY

    Sorry for the late response !
    Was down with Viral Fever!

    Wow all of these options work !

    DonkeyOte:

    With a UDF you need simply iterate (down) from 2^n to 2^0 and test to see if the iterated value (2^x) is <= remaining value to be apportioned appending the binary string with 1/0 as appropriate.


    As mentioned above, I had a small doubt of getting the "n"

    Example:

    If I have a Cell containing 8 then I know that 2^3 = 8 , however how do i get the answer n=3?I would be happy if you could answer it the same thread..


    I got the Solution it is LOG(8,2) which will gve me n=3...
    Last edited by e4excel; 06-22-2010 at 02:31 AM.

  7. #7
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: #Num Error while converting nos above 512 into BINARY

    Dear DonkeyOte,

    I am sure this works however How Do I use the UDF like I pasted your code In Sheet 1 and then in the Sheet 1 Typed 1010 in cell A1 and tried typing
    Please Login or Register  to view this content.
    but it did not work can u please advise how do I use it?
    Last edited by e4excel; 06-22-2010 at 02:31 AM.

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: #Num Error while converting nos above 512 into BINARY

    Quote Originally Posted by e4excel
    How Do I use the UDF like I pasted your code In Sheet 1 and then in the Sheet 1 Typed 1010 in cell A1 and tried typing...
    UDFs must be stored in Modules in VBE (Insert -> Module).

    Quote Originally Posted by e4excel
    If I have a Cell containing 8 then I know that 2^3 = 8 , however how do i get the answer n=3?I would be happy if you could answer it the same thread..
    I'm not entirely sure what the question is ... "n" per the UDF is simply the number of digits you want returned in your binary string.
    If you want to adjust "n" per the LOG of the value then modify the UDF as appropriate (dll illustrates this with the native function approach)
    Last edited by DonkeyOte; 06-22-2010 at 04:02 AM. Reason: added quotes

  9. #9
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: #Num Error while converting nos above 512 into BINARY

    Thanks for the explanation DO..and it works

    I was looking to get the value of n in the equation 2^n =8
    Now I know its 3..

    and I know its simple just by putting [ = log(8,2) ]

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: #Num Error while converting nos above 512 into BINARY

    Here's what I use:
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

+ 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