+ Reply to Thread
Results 1 to 10 of 10

#Num Error while converting nos above 512 into BINARY

Hybrid View

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

    #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,535

    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)

    Function DEC2BINLARGE(rngVal As Range, Optional lngPlaces As Long = 15)
    Dim lngPower As Long, lngRunning As Long, strBin As String
    For lngPower = lngPlaces - 1 To 0 Step -1
        If 2 ^ lngPower <= (Int(rngVal) - lngRunning) Then
            strBin = strBin & 1
            lngRunning = lngRunning + (2 ^ lngPower)
        Else
            strBin = strBin & 0
        End If
    Next lngPower
    DEC2BINLARGE = strBin
    End Function
    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
    Microsoft 365
    Posts
    14,864

    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,535

    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
    Microsoft 365
    Posts
    14,864

    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,522

    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.

+ 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