Dim $num1 = 0xADE1
Dim $num2 = 0x87B5
ConsoleWrite(_NumberToBinary($num1) & @CRLF)
ConsoleWrite(_NumberToBinary($num2) & @CRLF)
Func _NumberToBinary($iNumber)
Local $iTopBit, $sBinString = ""
If $iNumber < -2147483648 Or $iNumber > 4294967295 Then Return SetError(1, 0, "")
If $iNumber > 2147483647 Or $iNumber < 0 Then
$iTopBit = 1
Else
$iTopBit = 0
EndIf
Local $iUnsignedNumber = BitAND($iNumber, 0x7FFFFFFF)
Do
$sBinString = BitAND($iUnsignedNumber, 1) & $sBinString
$iUnsignedNumber = BitShift($iUnsignedNumber, 1)
Until Not $iUnsignedNumber
Return StringRegExpReplace($iTopBit & StringRight("000000000000000000000000000000" & $sBinString, 31), "(?m)^0+", "")
EndFunc ;==>_NumberToBinary
|