Jump to content

dec2bin | bin2dec


kaesereibe
 Share

Recommended Posts

Dec 2 Bin (Decimal to Binary)

This shows an another alternate function for dec to bin

Func Dec2Bin($D)
    Return (BitShift($D, 1) ? Dec2Bin(BitShift($D, 1)) : "") & BitAnd($D, 1)
EndFunc    ;==> Dec2Bin() AutoIt v3.3.12.0

MsgBox(0, "Dec2Bin", Dec2Bin(1337) & " | " & Dec2Bin(15))               ; ==> 10100111001 | 1111

or (thx to AspirinJunkie)

 

Func Dec2Bin2($D)
    Return $D ? Dec2Bin2(BitShift($D, 1)) & BitAnd($D, 1) : ""
EndFunc    ;==> Dec2Bin() AutoIt v3.3.12.0

MsgBox(0, "Dec2Bin", Dec2Bin2(1337) & " | " & Dec2Bin2(15))               ; ==> 10100111001 | 1111

Bin 2 Dec (Binary to Decimal)

This shows an another alternate function for bin to dec

Func Bin2Dec($B)
    Return BitOr((StringLen($B) > 1 ? BitShift(Bin2Dec(StringTrimRight($B, 1)), -1) : 0), StringRight($B, 1))
EndFunc    ;==> Bin2Dec() AutoIt v3.3.12.0

MsgBox(0, "Bin2Dec", Bin2Dec(10100111001) & " | " & Bin2Dec(1111))        ; ==> 1337 | 15
Edited by kaesereibe
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...