求助,按位反方向读取二进制数,怎么做?
例如将0xADE1
1010 1101 1110 0001
变成0x87B5
1000 0111 1011 0101
有大神知道吗? 回复 1# sh2288
注意
返回值
是hex值,不是文本string值 回复 1# sh2288
注意
返回值
是hex值,不是文本string值
现在我可以返回87b5,但是是string值
怎么变为hex值? 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 回复 4# haijie1223
强~~~!
大神{:face (88):}
页:
[1]