au3怎样把2进制转换成16进制(已解决)
本帖最后由 fuldho 于 2016-2-26 10:41 编辑如:111=7
111111111111111111111=1FFFFF 是这样么?
本帖最后由 lpxx 于 2016-2-24 22:48 编辑
我自己收集整理的,非原创。原作者是德国au3牛人UZE,原版找不到了。
;#NoTrayIcon
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
$Form1 = GUICreate("进制转换器", 489, 599, 195, 135)
$Group1 = GUICtrlCreateGroup("转换器/ASCII码/十进制/十六进制", 5, 5, 473, 425)
$Edit1 = GUICtrlCreateEdit("", 16, 25, 449, 89)
GUICtrlSetData(-1, "在这里你输入需要转换的字符")
$Btn1 = GUICtrlCreateButton("转换", 16, 209, 300, 50, $WS_GROUP)
GUICtrlSetFont(-1, 16, 800, 0, "Comic Sans MS")
$Btn3E = GUICtrlCreateButton("删除", 320, 209, 149, 50, $WS_GROUP)
GUICtrlSetFont(-1, 16, 800, 0, "Comic Sans MS")
$Edit2 = GUICtrlCreateEdit("", 16, 268, 449, 89)
GUICtrlSetData(-1, "")
$Label1 = GUICtrlCreateLabel("Ascii", 21, 121, 47, 31)
GUICtrlSetFont(-1, 14, 800, 0, "Comic Sans MS")
$ASCii1 = GUICtrlCreateRadio("十进制", 21, 145, 100, 17)
GUICtrlSetState($ASCii1, $GUI_CHECKED)
$ASCii2 = GUICtrlCreateRadio("十六进制", 21, 166, 100, 17)
$ASCii3 = GUICtrlCreateRadio("二进制", 21, 187, 100, 17)
$Label2 = GUICtrlCreateLabel("十进制", 125, 121, 75, 31)
GUICtrlSetFont(-1, 14, 800, 0, "Comic Sans MS")
$Dec1 = GUICtrlCreateRadio("ASCII码", 125, 145, 100, 17)
$Dec2 = GUICtrlCreateRadio("十六进制", 125, 166, 100, 17)
$Dec3 = GUICtrlCreateRadio("二进制", 125, 187, 100, 17)
$Label3 = GUICtrlCreateLabel("十六进制", 230, 121, 120, 31)
GUICtrlSetFont(-1, 14, 800, 0, "Comic Sans MS")
$Hexa1 = GUICtrlCreateRadio("ASCII码", 230, 145, 100, 17)
$Hexa2 = GUICtrlCreateRadio("十进制", 230, 166, 100, 17)
$Hexa3 = GUICtrlCreateRadio("二进制", 230, 187, 100, 17)
$Label4 = GUICtrlCreateLabel("二进制", 360, 119, 67, 31)
GUICtrlSetFont(-1, 14, 800, 0, "Comic Sans MS")
$Bin1 = GUICtrlCreateRadio("ASCII码", 360, 145, 100, 17)
$Bin2 = GUICtrlCreateRadio("十进制", 360, 166, 100, 17)
$Bin3 = GUICtrlCreateRadio("十六进制", 360, 187, 100, 17)
$Btn2 = GUICtrlCreateButton("复制", 16, 367, 449, 50, $WS_GROUP)
GUICtrlSetFont(-1, 16, 800, 0, "Comic Sans MS")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Edit3 = GUICtrlCreateEdit("", 5, 440, 473, 145)
GUICtrlSetData(-1, "")
GUICtrlSetFont(-1, 10, 800, 0, "Comic Sans MS")
GUICtrlSetColor(-1, 0xC0DCC0)
GUICtrlSetBkColor(-1, 0x000000)
GUISetState(@SW_SHOW)
ConsoleWrite(" ____ __ __ " & @LF)
ConsoleWrite("/\_`\ /\ \ /\ \ " & @LF)
ConsoleWrite("\ \ \L\ \____ \ \ \ ___ ___ ___\ \ \/'\ ____ ____" & @LF)
ConsoleWrite(" \ \_ <'/\ \/\ \ \ \ \__/ __`\/ __`\/'___\ \ , </\ \/\ \/',__\ " & @LF)
ConsoleWrite("\ \ \L\ \ \ \_\ \ \ \ \L\ \/\ \L\ \/\ \L\ \/\ \__/\ \ \\`\\ \ \_\ \/\__, `\" & @LF)
ConsoleWrite(" \ \____/\/`____ \ \ \____/\ \____/\ \____/\ \____\\ \_\ \_\/`____ \/\____/" & @LF)
ConsoleWrite(" \/___/`/___/> \ \/___/\/___/\/___/\/____/ \/_/\/_/`/___/> \/___/ " & @LF)
ConsoleWrite(" /\___/ /\___/ " & @LF)
ConsoleWrite(" \/__/ \/__/ " & @LF)
ConsoleWrite("-------------------------------------------------------------------------------" & @LF & @LF)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Btn1
_Btn1()
Case $Btn2
_Btn2()
Case $Btn3E
GUICtrlSetData($Edit1, "")
EndSwitch
WEnd
Func _Btn1()
If GUICtrlRead($ASCii1) = 1 Then
Global $Saisie
$Saisie = GUICtrlRead($Edit1)
$Nbr = StringLen($Saisie)
If ($Nbr <= 0) Then
MsgBox(48, "错误", "你没有输入任何字符")
Else
$Flag1 = StringSplit($Saisie, "")
$Flag2 = _ArrayToString($Flag1, " ")
$Flag3 = StringSplit($Flag2, " ")
Dim $Tab1[$Flag3]
Dim $Tab2[$Flag3]
For $i = 0 To $Flag3 - 1 Step 1
$Tab1[$i] = $Flag1[$i + 1]
If ($Flag1[$i + 1] = "") Then
$Tab1[$i] = " "
EndIf
$Tab2[$i] = AscW($Tab1[$i])
Next
$TabR1 = _ArrayToString($Tab1, "")
$TabR2 = _ArrayToString($Tab2, " ")
GUICtrlSetData($Edit2, $TabR2)
ConsoleWrite("消息: " & $Saisie & @LF & @LF & "ASCII十进制转换消息: " & $TabR2 & @LF)
ConsoleWrite("-------------------------------------------------------------------------------" & @LF & @LF)
EndIf
EndIf
If GUICtrlRead($ASCii2) = 1 Then
Global $Saisie
$Saisie = GUICtrlRead($Edit1)
$Nbr = StringLen($Saisie)
If ($Nbr <= 0) Then
MsgBox(48, "错误", "你没有输入任何字符")
Else
$Flag1 = StringSplit($Saisie, "")
$Flag2 = _ArrayToString($Flag1, " ")
$Flag3 = StringSplit($Flag2, " ")
Dim $Tab1[$Flag3]
Dim $Tab2[$Flag3]
For $i = 0 To $Flag3 - 1 Step 1
$Tab1[$i] = $Flag1[$i + 1]
If ($Flag1[$i + 1] = "") Then
$Tab1[$i] = " "
EndIf
$Tab2[$i] = Hex(AscW($Tab1[$i]))
Next
$TabR1 = _ArrayToString($Tab1, "")
$TabR2 = _ArrayToString($Tab2, " ")
GUICtrlSetData($Edit2, $TabR2)
ConsoleWrite("信息: " & $Saisie & @LF & @LF & "十六进制的ASCII码转换信息: " & $TabR2 & @LF)
ConsoleWrite("-------------------------------------------------------------------------------" & @LF & @LF)
EndIf
EndIf
If GUICtrlRead($ASCii3) = 1 Then
Global $Saisie
$Saisie = GUICtrlRead($Edit1)
$Nbr = StringLen($Saisie)
If ($Nbr <= 0) Then
MsgBox(48, "错误", "你没有输入任何字符")
Else
$Flag1 = StringSplit($Saisie, "")
$Flag2 = _ArrayToString($Flag1, " ")
$Flag3 = StringSplit($Flag2, " ")
Dim $Tab1[$Flag3]
Dim $Tab2[$Flag3]
For $i = 0 To $Flag3 - 1 Step 1
$Tab1[$i] = $Flag1[$i + 1]
If ($Flag1[$i + 1] = "") Then
$Tab1[$i] = " "
EndIf
$Tab2[$i] = Dec2Bin(AscW($Tab1[$i]))
Next
$TabR1 = _ArrayToString($Tab1, "")
$TabR2 = _ArrayToString($Tab2, " ")
GUICtrlSetData($Edit2, $TabR2)
ConsoleWrite("信息: " & $Saisie & @LF & @LF & "二进制ASCII码的转换信息: " & $TabR2 & @LF)
ConsoleWrite("-------------------------------------------------------------------------------" & @LF & @LF)
EndIf
EndIf
If GUICtrlRead($Dec1) = 1 Then
Global $Saisie
$Saisie = GUICtrlRead($Edit1)
$Nbr = StringLen($Saisie)
If ($Nbr <= 0) Then
MsgBox(48, "错误", "你没有输入任何字符")
Else
$Flag1 = StringSplit($Saisie, " ")
$Flag2 = _ArrayToString($Flag1, " ")
$Flag3 = StringSplit($Flag2, " ")
Dim $Tab1[$Flag3]
Dim $Tab2[$Flag3]
For $i = 0 To $Flag3 - 1 Step 1
$Tab1[$i] = $Flag1[$i + 1]
If ($Flag1[$i + 1] = "") Then
$Tab1[$i] = "32"
EndIf
$Tab2[$i] = ChrW($Tab1[$i])
Next
$TabR1 = _ArrayToString($Tab1, "")
$TabR2 = _ArrayToString($Tab2, "")
If Not StringRegExp($TabR1, '[^0123456789]') Then
GUICtrlSetData($Edit2, $TabR2)
ConsoleWrite("信息: " & $Saisie & @LF & @LF & "十进制ASCII的转换信息: " & $TabR2 & @LF)
ConsoleWrite("-------------------------------------------------------------------------------" & @LF & @LF)
Else
MsgBox(48, "十进制错误", "输入必须包含" & @LF & "以下字符 : 0,1,2,3,4,5,6,7,8,9")
EndIf
EndIf
EndIf
If GUICtrlRead($Dec2) = 1 Then
Global $Saisie
$Saisie = GUICtrlRead($Edit1)
$Nbr = StringLen($Saisie)
If ($Nbr <= 0) Then
MsgBox(48, "错误", "你没有输入任何字符")
Else
$Flag1 = StringSplit($Saisie, " ")
$Flag2 = _ArrayToString($Flag1, " ")
$Flag3 = StringSplit($Flag2, " ")
Dim $Tab1[$Flag3]
Dim $Tab2[$Flag3]
For $i = 0 To $Flag3 - 1 Step 1
$Tab1[$i] = $Flag1[$i + 1]
If ($Flag1[$i + 1] = "") Then
$Tab1[$i] = "32"
EndIf
$Tab2[$i] = Hex($Tab1[$i])
Next
$TabR1 = _ArrayToString($Tab1, "")
$TabR2 = _ArrayToString($Tab2, " ")
If Not StringRegExp($TabR1, '[^0123456789]') Then
GUICtrlSetData($Edit2, $TabR2)
ConsoleWrite("信息: " & $Saisie & @LF & @LF & "十六进制转换十进制信息: " & $TabR2 & @LF)
ConsoleWrite("-------------------------------------------------------------------------------" & @LF & @LF)
Else
MsgBox(48, "错误十进制", "输入必须包含" & @LF & "以下字符 : 0,1,2,3,4,5,6,7,8,9")
EndIf
EndIf
EndIf
If GUICtrlRead($Dec3) = 1 Then
Global $Saisie
$Saisie = GUICtrlRead($Edit1)
$Nbr = StringLen($Saisie)
If ($Nbr <= 0) Then
MsgBox(48, "错误", "你没有输入任何字符")
Else
$Flag1 = StringSplit($Saisie, " ")
$Flag2 = _ArrayToString($Flag1, " ")
$Flag3 = StringSplit($Flag2, " ")
Dim $Tab1[$Flag3]
Dim $Tab2[$Flag3]
For $i = 0 To $Flag3 - 1 Step 1
$Tab1[$i] = $Flag1[$i + 1]
If ($Flag1[$i + 1] = "") Then
$Tab1[$i] = "32"
EndIf
$Tab2[$i] = Dec2Bin($Tab1[$i])
Next
$TabR1 = _ArrayToString($Tab1, "")
$TabR2 = _ArrayToString($Tab2, " ")
If Not StringRegExp($TabR1, '[^0123456789]') Then
GUICtrlSetData($Edit2, $TabR2)
ConsoleWrite("信息: " & $Saisie & @LF & @LF & "十进制转换成二进制的信息: " & $TabR2 & @LF)
ConsoleWrite("-------------------------------------------------------------------------------" & @LF & @LF)
Else
MsgBox(48, "错误十进制", "输入必须包含" & @LF & "以下字符 : 0,1,2,3,4,5,6,7,8,9")
EndIf
EndIf
EndIf
If GUICtrlRead($Hexa1) = 1 Then
Global $Saisie
$Saisie = StringUpper(GUICtrlRead($Edit1))
$Nbr = StringLen($Saisie)
If ($Nbr <= 0) Then
MsgBox(48, "错误", "你没有输入任何字符")
Else
$Flag1 = StringSplit($Saisie, " ")
$Flag2 = _ArrayToString($Flag1, " ")
$Flag3 = StringSplit($Flag2, " ")
Dim $Tab1[$Flag3]
Dim $Tab2[$Flag3]
For $i = 0 To $Flag3 - 1 Step 1
$Tab1[$i] = $Flag1[$i + 1]
If ($Flag1[$i + 1] = "") Then
$Tab1[$i] = "20"
EndIf
$Tab2[$i] = ChrW(Dec($Tab1[$i]))
Next
$TabR1 = _ArrayToString($Tab1, "")
$TabR2 = _ArrayToString($Tab2, "")
If Not StringRegExp($TabR1, '[^0123456789ABCDEF]') Then
GUICtrlSetData($Edit2, $TabR2)
ConsoleWrite("信息: " & $Saisie & @LF & @LF & "转换成十六进制ASCII信息: " & $TabR2 & @LF)
ConsoleWrite("-------------------------------------------------------------------------------" & @LF & @LF)
Else
MsgBox(48, "十六进制错误", "输入必须包含" & @LF & "以下字符 : 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F")
EndIf
EndIf
EndIf
If GUICtrlRead($Hexa2) = 1 Then
Global $Saisie
$Saisie = StringUpper(GUICtrlRead($Edit1))
$Nbr = StringLen($Saisie)
If ($Nbr <= 0) Then
MsgBox(48, "错误", "你没有输入任何字符")
Else
$Flag1 = StringSplit($Saisie, " ")
$Flag2 = _ArrayToString($Flag1, " ")
$Flag3 = StringSplit($Flag2, " ")
Dim $Tab1[$Flag3]
Dim $Tab2[$Flag3]
For $i = 0 To $Flag3 - 1 Step 1
$Tab1[$i] = $Flag1[$i + 1]
If ($Flag1[$i + 1] = "") Then
$Tab1[$i] = "20"
EndIf
$Tab2[$i] = Dec($Tab1[$i])
Next
$TabR1 = _ArrayToString($Tab1, "")
$TabR2 = _ArrayToString($Tab2, " ")
If Not StringRegExp($TabR1, '[^0123456789ABCDEF]') Then
GUICtrlSetData($Edit2, $TabR2)
ConsoleWrite("信息: " & $Saisie & @LF & @LF & "十六进制转换十进制信息: " & $TabR2 & @LF)
ConsoleWrite("-------------------------------------------------------------------------------" & @LF & @LF)
Else
MsgBox(48, "十六进制错误", "输入必须包含" & @LF & "以下字符 : 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F")
EndIf
EndIf
EndIf
If GUICtrlRead($Hexa3) = 1 Then
Global $Saisie
$Saisie = StringUpper(GUICtrlRead($Edit1))
$Nbr = StringLen($Saisie)
If ($Nbr <= 0) Then
MsgBox(48, "错误", "你没有输入任何字符")
Else
$Flag1 = StringSplit($Saisie, " ")
$Flag2 = _ArrayToString($Flag1, " ")
$Flag3 = StringSplit($Flag2, " ")
Dim $Tab1[$Flag3]
Dim $Tab2[$Flag3]
For $i = 0 To $Flag3 - 1 Step 1
$Tab1[$i] = $Flag1[$i + 1]
If ($Flag1[$i + 1] = "") Then
$Tab1[$i] = "20"
EndIf
$Tab2[$i] = Dec2Bin(Dec($Tab1[$i]))
Next
$TabR1 = _ArrayToString($Tab1, "")
$TabR2 = _ArrayToString($Tab2, " ")
If Not StringRegExp($TabR1, '[^0123456789ABCDEF]') Then
GUICtrlSetData($Edit2, $TabR2)
ConsoleWrite("信息: " & $Saisie & @LF & @LF & "十六进制转换成二进制信息: " & $TabR2 & @LF)
ConsoleWrite("-------------------------------------------------------------------------------" & @LF & @LF)
Else
MsgBox(48, "错误十六进制", "输入必须包含" & @LF & "以下字符 : 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F")
EndIf
EndIf
EndIf
If GUICtrlRead($Bin1) = 1 Then
Global $CodeBinaire = GUICtrlRead($Edit1)
$Nbr = StringLen($CodeBinaire)
If ($Nbr <= 0) Then
MsgBox(48, "错误", "你没有输入任何字符")
Else
Global $Bool = True
$Flag1 = StringSplit($CodeBinaire, " ")
$Flag2 = _ArrayToString($Flag1, " ")
$Flag3 = StringSplit($Flag2, " ")
Dim $Tab1[$Flag3]
For $i = 0 To $Flag3 - 1 Step 1
$Tab1[$i] = $Flag1[$i + 1]
If ($Flag1[$i + 1] = "") Then
$Tab1[$i] = "100000"
EndIf
Next
Dim $TabF[$Flag3]
For $a = 0 To $Flag3 - 1 Step 1
If Not StringRegExp($Tab1[$a], '[^01]') Then
$Flag4 = StringSplit($Tab1[$a], "")
$Nbr2 = StringLen($Tab1[$a])
Global $V1 = 1
Dim $Tab2[$Nbr2]
$Tab2 = "1"
For $i = 1 To $Nbr2 - 1 Step 1
$V1 *= 2
$Tab2[$i] = $V1
Next
$Rtab2 = _ArrayToString($Tab2)
$V1 = 1
Local $V2
For $i = $Flag4 To 1 Step -1
$V2 &= $Flag4[$i]
Next
$Flag5 = StringSplit($V2, "")
$V2 = ""
Global $V3
Dim $Tab3[$Nbr2]
For $i = 0 To $Nbr2 - 1 Step 1
$Tab3[$i] = $Flag5[$i + 1]
If ($Tab3[$i] = "1") Then
$V3 += $Tab2[$i]
EndIf
Next
$ChrW = ChrW($V3)
$TabF[$a] = $ChrW
$V3 = ""
Else
$Bool = False
EndIf
Next
If ($Bool = True) Then
$ResultatFinal = _ArrayToString($TabF, "")
GUICtrlSetData($Edit2, $ResultatFinal)
ConsoleWrite("信息: " & $Saisie & @LF & @LF & "转换成二进制信息: " & $TabR2 & @LF)
ConsoleWrite("-------------------------------------------------------------------------------" & @LF & @LF)
Else
MsgBox(48, "错误 二进制", "输入必须包含" & @LF & "以下字符 : 0,1")
EndIf
EndIf
EndIf
If GUICtrlRead($Bin2) = 1 Then
Global $CodeBinaire = GUICtrlRead($Edit1)
$Nbr = StringLen($CodeBinaire)
If ($Nbr <= 0) Then
MsgBox(48, "错误", "你没有输入任何字符")
Else
Global $Bool = True
$Flag1 = StringSplit($CodeBinaire, " ")
$Flag2 = _ArrayToString($Flag1, " ")
$Flag3 = StringSplit($Flag2, " ")
Dim $Tab1[$Flag3]
For $i = 0 To $Flag3 - 1 Step 1
$Tab1[$i] = $Flag1[$i + 1]
If ($Flag1[$i + 1] = "") Then
$Tab1[$i] = "100000"
EndIf
Next
Dim $TabF[$Flag3]
For $a = 0 To $Flag3 - 1 Step 1
If Not StringRegExp($Tab1[$a], '[^01]') Then
$Flag4 = StringSplit($Tab1[$a], "")
$Nbr2 = StringLen($Tab1[$a])
Global $V1 = 1
Dim $Tab2[$Nbr2]
$Tab2 = "1"
For $i = 1 To $Nbr2 - 1 Step 1
$V1 *= 2
$Tab2[$i] = $V1
Next
$Rtab2 = _ArrayToString($Tab2)
$V1 = 1
Local $V2
For $i = $Flag4 To 1 Step -1
$V2 &= $Flag4[$i]
Next
$Flag5 = StringSplit($V2, "")
$V2 = ""
Global $V3
Dim $Tab3[$Nbr2]
For $i = 0 To $Nbr2 - 1 Step 1
$Tab3[$i] = $Flag5[$i + 1]
If ($Tab3[$i] = "1") Then
$V3 += $Tab2[$i]
EndIf
Next
$TabF[$a] = $V3 & " "
$V3 = ""
Else
$Bool = False
EndIf
Next
If ($Bool = True) Then
$ResultatFinal = _ArrayToString($TabF, "")
GUICtrlSetData($Edit2, $ResultatFinal)
ConsoleWrite("Message: " & $Saisie & @LF & @LF & "十进制转换二进制信息: " & $TabR2 & @LF)
ConsoleWrite("-------------------------------------------------------------------------------" & @LF & @LF)
Else
MsgBox(48, "二进制错误", "输入必须包含" & @LF & "以下字符 : 0,1")
EndIf
EndIf
EndIf
If GUICtrlRead($Bin3) = 1 Then
Global $CodeBinaire = GUICtrlRead($Edit1)
$Nbr = StringLen($CodeBinaire)
If ($Nbr <= 0) Then
MsgBox(48, "错误", "你没有输入任何字符")
Else
Global $Bool = True
$Flag1 = StringSplit($CodeBinaire, " ")
$Flag2 = _ArrayToString($Flag1, " ")
$Flag3 = StringSplit($Flag2, " ")
Dim $Tab1[$Flag3]
For $i = 0 To $Flag3 - 1 Step 1
$Tab1[$i] = $Flag1[$i + 1]
If ($Flag1[$i + 1] = "") Then
$Tab1[$i] = "100000"
EndIf
Next
Dim $TabF[$Flag3]
For $a = 0 To $Flag3 - 1 Step 1
If Not StringRegExp($Tab1[$a], '[^01]') Then
$Flag4 = StringSplit($Tab1[$a], "")
$Nbr2 = StringLen($Tab1[$a])
Global $V1 = 1
Dim $Tab2[$Nbr2]
$Tab2 = "1"
For $i = 1 To $Nbr2 - 1 Step 1
$V1 *= 2
$Tab2[$i] = $V1
Next
$Rtab2 = _ArrayToString($Tab2)
$V1 = 1
Local $V2
For $i = $Flag4 To 1 Step -1
$V2 &= $Flag4[$i]
Next
$Flag5 = StringSplit($V2, "")
$V2 = ""
Global $V3
Dim $Tab3[$Nbr2]
For $i = 0 To $Nbr2 - 1 Step 1
$Tab3[$i] = $Flag5[$i + 1]
If ($Tab3[$i] = "1") Then
$V3 += $Tab2[$i]
EndIf
Next
$hex = Hex("0x" & $V3)
$TabF[$a] = $hex & " "
$V3 = ""
Else
$Bool = False
EndIf
Next
If ($Bool = True) Then
$ResultatFinal = _ArrayToString($TabF, "")
GUICtrlSetData($Edit2, $ResultatFinal)
ConsoleWrite("信息: " & $Saisie & @LF & @LF & "十六进制转换二进制信息: " & $TabR2 & @LF)
ConsoleWrite("-------------------------------------------------------------------------------" & @LF & @LF)
Else
MsgBox(48, "错误二进制", "输入必须包含" & @LF & "以下字符 : 0,1")
EndIf
EndIf
EndIf
EndFunc ;==>_Btn1
Func _Btn2()
GUICtrlSetData($Edit3, "数据 : " & GUICtrlRead($Edit2))
ClipPut(GUICtrlRead($Edit2))
EndFunc ;==>_Btn2
Func Dec2Bin($iNumber)
Local $sRet = ""
Do
$sRet = BitAND($iNumber, 1) & $sRet
$iNumber = BitShift($iNumber, 1)
Until $iNumber = 0
Return $sRet
EndFunc ;==>Dec2Bin
本帖最后由 afan 于 2016-2-25 00:15 编辑
Local $s0 ='111'
Local $s1 ='111111111111111111111'
Msgbox(0, _2To16($s0), _2To16($s1))
Func _2To16($sBN)
If Not StringRegExp($sBN, '^+$') Then Return SetError(1)
$sBN = '000' & $sBN
$sBN = StringTrimLeft($sBN, Mod(StringLen($sBN), 4))
Local $aSN = StringRegExp($sBN, '....', 3)
Local $sOut = '', $v, $i, $j
For $i = 0 To UBound($aSN) - 1
$v = StringMid($aSN[$i], 1, 1)
For $j = 1 to 3
$v = $v * 2 + StringMid($aSN[$i], $j + 1, 1)
Next
$sOut &= StringMid('0123456789ABCDEF', $v + 1, 1)
Next
Return $sOut
EndFunc ;==>_2To16 回复 4# afan
学习了 回复 5# zldfsz
好久不见 回复 6# haijie1223
{:face (303):}
回帖收藏!! afan的方法很不错,谢谢 学习下。。。。。。。。。。。 回复 4# afan
好像以前用过,挺好使... 回复 3# lpxx
谢谢分享!收藏了 回复 11# 邪恶海盗
没有吧,这个是现写的。好像以前写过类似的十进制与其它进制间的转换,可能都查不多吧,所以眼熟而已 ^ ^ 版主出马立即解决,看我的笨办法.. For $h = 1 To $R Step 4
$he = StringMid($strExt1, $h, 4)
If $he = "0000" Then $hex = "0"
If $he = "0001" Then $hex = "1"
If $he = "0010" Then $hex = "2"
If $he = "0011" Then $hex = "3"
If $he = "0100" Then $hex = "4"
If $he = "0101" Then $hex = "5"
If $he = "0110" Then $hex = "6"
If $he = "0111" Then $hex = "7"
If $he = "1000" Then $hex = "8"
If $he = "1001" Then $hex = "9"
If $he = "1010" Then $hex = "A"
If $he = "1011" Then $hex = "B"
If $he = "1100" Then $hex = "C"
If $he = "1101" Then $hex = "D"
If $he = "1110" Then $hex = "E"
If $he = "1111" Then $hex = "F"
Next回复 4# afan 回复 14# fuldho
这个很直观 呵呵
不过,前面应该还需要先整理成4的倍数位,不然就全错了
页:
[1]
2