Search notes:

Excel conversion functions (x2y)

Excel has some conversion functions whose name generally is x2y, for example dec2bin which converts a decimal number to its binary representation.

Demonstration of dec2bin

The following example tries to demonstrate dec2bin.
Unfortunately, as the second row shows, dec2bin cannot convert a number greater then 511, it causes a #NUM! cell error.
Therefore, the third row concatenates two results of dec2bin with the concatenation operator &.
option explicit

sub main() ' {

    cells(1, 1) = 500
    cells(1, 2).formulaR1C1 = "=dec2bin(rc[-1])"

    cells(2, 1) = 512
    cells(2, 2).formulaR1C1 = "=dec2bin(rc[-1])"

    cells(3, 1) = 123456
    cells(3, 2).formulaR1C1 = "=dec2bin(int(rc[-1]/512), 9) & " & _
                               "dec2bin(mod(rc[-1],512), 9)"

    with columns(2)

       .horizontalAlignment = xlRight
       .select
        with selection.font
             .name = "Courier New"
             .bold = true
        end with

       .autoFit
    end with

    cells(5, 5).select

end sub ' }
Github repository about-Excel, path: /functions/x2y/dec2bin.bas

Misc

In German versions of Excel, dec2bin is called dezinbin

See also

Other conversion functions
Excel functions

Index