Jump to content

Binary as InputBox to decimal and hex?


Recommended Posts

31 minutes ago, Musashi said:

The solutions from @JockoDundee, @Nine and @Chimp only work if you specify exactly 8 bits.

Not in my case, it is based on StringLen which could be anything.  Moreover it allows any bases from 2 to 16.  Take a closer look. :ermm:

Link to comment
Share on other sites

 

Just now, JockoDundee said:

Free your mind from conceptual limitations, and all sorts of solutions will appear :)

lol, I do understand that arrays are said to be significantly faster. such as how you did it just in general programming. 

It's significantly slower, but is doing more too. I think this maybe the most practical approach.  

Global $iIter = 100000, $sOut, $t = TimerInit()

Global Enum $0000, $0001, $0010, $0011, $0100, $0101, $0110, $0111, $1000, $1001
Global Const $1010 = "A", $1011 = "B", $1100 = "C", $1101 = "D", $1110 = "E", $1111 = "F", $cow = "mooo"
Global Const $dataStream = "1110111110101101010011010100"


For $n = 1 To $iIter
    Global $sbyte = $dataStream
    Local $bArray[StringLen ( $sbyte )/4+1]
    $bArray[0] = (StringLen ( $sbyte )/4)
    for $z = 1 To $bArray[0]
    $bArray[$z] = Eval(StringLeft($sbyte, 4))
    $sbyte = StringTrimLeft ( $sbyte, 4 )
    Next
Next

$t = TimerDiff($t)

For $z = 1 To $bArray[0]
ConsoleWrite(" Check: " & $bArray[$z] & " Dec:" &Dec($bArray[$z])& " " &@CRLF )
Next

ConsoleWrite($iIter & " Iterations in " & $t / 1000 & " Seconds" & @CRLF & @CRLF)

 

Link to comment
Share on other sites

To be clear to those who bemoan the inflexibility of my solution, understand that the gloves came off the moment the OP said:

Quote

Considering speed as a factor...

At that point, a version which provided a 2x speed up over the best effort so far, was entirely on the mark :)

 

Code hard, but don’t hard code...

Link to comment
Share on other sites

1 hour ago, Musashi said:

Here, just for comparison, are the runtime results on my stone-age PC

Can you run again?  The relative order doesn't match mine:

Based on code from: JockoDundee
 Check: AA 170
 100000 Iterations in 0.2239925 Seconds

Based on code from: Chimp
 Check: AA 170
 100000 Iterations in 0.2703542 Seconds

Based on code from: jhcd
 Check: 00000000000000AA 170
 100000 Iterations in 0.6339325 Seconds

Based on code from: nine
 Check: 000000AA 170
 100000 Iterations in 1.1458971 Seconds

Based on code from: Musashi
 Check: 000000AA 170
 100000 Iterations in 1.4233144 Seconds

Its hard to imagine Eval's being quicker than direct array access.

Code hard, but don’t hard code...

Link to comment
Share on other sites

40 minutes ago, Nine said:

Not in my case, it is based on StringLen which could be anything.  Moreover it allows any bases from 2 to 16.  Take a closer look. :ermm:

You are correct, please accept my heartfelt apologies ;).

I used the code that Jocko attached in his runtime tests :

Local $sBasedOn="nine", $iIter=100000, $sOut, $t=TimerInit()
Local $input="10101010", $bin, $ival, $iLen=8, $base=2

For $n=1 To $iIter
  $iVal = 0

  For $i = 0 to $iLen - 1
    $iVal += Dec(StringMid($input, $iLen - $i, 1)) * ($base^$i)
  Next

  $sOut=Hex(Int($iVal)) &" "&  Int($iVal)

Next

$t=TimerDiff($t)

ConsoleWrite("Based on code from: "& $sBasedOn & @CRLF& " Check: "& $sOut &" "& @CRLF &" "& $iIter &" Iterations in "& $t/1000  &" Seconds" &@CRLF&@CRLF)

(there you have to enter 8 bits)

Your original code works flawlessly.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

Just now, Musashi said:

I used the code that Jocko attached in his runtime tests :

I modified his code to give it the best  result possible speedwise.  No offence was intended.  I also mentioned this when I did it.

Code hard, but don’t hard code...

Link to comment
Share on other sites

26 minutes ago, JockoDundee said:

... to those who bemoan the inflexibility of my solution ...

[...]

I modified his code to give it the best  result possible speedwise.  No offence was intended.  I also mentioned this when I did it.

In advance :
There was never any intention to judge your solution as inflexible or to consider your code customization as an offense. You should know me well enough by now ;).  

All solutions fulfill the original requirement of @major_lee !

I just wanted to point out, that some solutions also take variable bit lengths into consideration (no more and no less).

26 minutes ago, JockoDundee said:

Can you run again?  The relative order doesn't match mine. [...] Its hard to imagine Eval's being quicker than direct array access.

I will do that right after dinner.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

Link to comment
Share on other sites

48 minutes ago, Musashi said:

There was never any intention to judge your solution as inflexible or to consider your code customization as an offense. You should know me well enough by now ;).  

yes of course.  :) 
If I sounded defensive it’s just because I don’t take lightly modifying others code, but in this case I felt if I didn’t, it would be unfair.

Code hard, but don’t hard code...

Link to comment
Share on other sites

1 hour ago, JockoDundee said:

Can you run again?  The relative order doesn't match mine. Its hard to imagine Eval's being quicker than direct array access.

Here are the results :

I used the current code from @Chimp and the one you attached to your post. 3 runs each, with 100,000 and 1,000,000 iterations.

Spoiler

Based on code from: JockoDundee
 Check: AA 170
Trial 1 : 100000 Iterations in 0.672229334849915 Seconds
Trial 2 : 100000 Iterations in 0.695298712387871 Seconds
Trial 3 : 100000 Iterations in 0.654555149199021 Seconds

Trial 1 : 1000000 Iterations in 6.23055541014638 Seconds
Trial 2 : 1000000 Iterations in 6.19899393218473 Seconds
Trial 3 : 1000000 Iterations in 6.30784528241633 Seconds

--------------------------------------------------------
Based on code from: Chimp
 Check: AA 170
Trial 1 : 100000 Iterations in 0.535104653833072 Seconds
Trial 2 : 100000 Iterations in 0.531542143656257 Seconds
Trial 3 : 100000 Iterations in 0.528054077131515 Seconds

Trial 1 : 1000000 Iterations in 5.32384224995548 Seconds
Trial 2 : 1000000 Iterations in 5.32383199093629 Seconds
Trial 3 : 1000000 Iterations in 5.32107468224003 Seconds

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

3 hours ago, Musashi said:

I used the current code from @Chimp and the one you attached to your post. 3 runs each, with 100,000 and 1,000,000 iterations.

Thanks!  and good catch on the ‘E’.   
I reran as well, and still showing the opposite by about 10%. 

Though, looking at my code, I realize there is an implied conversion from string to int that I didn’t see before.  are you compiling 64-bit or 32-bit?  any other flags?

@Chimp, did you see any performance difference between the two on your machine?

btw, another version I tried initially was with 16 functions and Execute, though it was pretty slow.

 

Code hard, but don’t hard code...

Link to comment
Share on other sites

Here are my result with three same baseline test.

Quote

Based on code from: nine
 Check: 000000AA 170 
 1000000 Iterations in 18.0934664 Seconds
Based on code from: nine
 Check: 000000AA 170 
 1000000 Iterations in 17.3470087 Seconds
Based on code from: nine
 Check: 000000AA 170 
 1000000 Iterations in 17.2345381 Seconds

Local $sBasedOn="nine", $iIter=1000000, $sOut, $t=TimerInit()
Local $input="10101010", $bin, $ival, $iLen=8, $base=2

For $n=1 To $iIter
  $iVal = 0

  For $i = 0 to $iLen - 1
    $iVal += Dec(StringMid($input, $iLen - $i, 1)) * ($base^$i)
  Next

  $sOut=Hex(Int($iVal)) &" "&  Int($iVal)

Next

$t=TimerDiff($t)

ConsoleWrite("Based on code from: "& $sBasedOn & @CRLF& " Check: "& $sOut &" "& @CRLF &" "& $iIter &" Iterations in "& $t/1000  &" Seconds" &@CRLF&@CRLF)

 

Quote

Based on code from: jhcd
 Check: 00000000000000AA 170 
 1000000 Iterations in 12.155069 Seconds
Based on code from: jhcd
 Check: 00000000000000AA 170 
 1000000 Iterations in 11.0118714 Seconds
Based on code from: jhcd
 Check: 00000000000000AA 170 
 1000000 Iterations in 9.2977334 Seconds

Local $sBasedOn="jhcd", $iIter=1000000, $sOut, $t=TimerInit()

Local $input="10101010", $bin, $aDll=DllOpen("msvcrt.dll")

For $n=1 To $iIter

  $bin=DllCall($aDll, "int64:cdecl", "_wcstoi64", "wstr", $input, "ptr*", 0, "int", 2)[0]
  $sOut=Hex($bin) &" "& $bin

Next
$t=TimerDiff($t)
ConsoleWrite("Based on code from: "& $sBasedOn & @CRLF& " Check: "& $sOut &" "& @CRLF &" "& $iIter &" Iterations in "& $t/1000  &" Seconds" &@CRLF&@CRLF)
Quote

Based on code from: Musashi
 Check: 000000AA 170 
 1000000 Iterations in 21.2172401 Seconds
Based on code from: Musashi
 Check: 000000AA 170 
 1000000 Iterations in 21.3587079 Seconds
Based on code from: Musashi
 Check: 000000AA 170 
 1000000 Iterations in 20.9960947 Seconds

Local $sBasedOn="Musashi", $iIter=1000000, $sOut, $t=TimerInit()

Local $input="10101010", $aArr, $dec

For $n=1 To $iIter
    $aArr = StringSplit($input, "", 2)
    $dec = 0
    For $i = UBound($aArr) - 1 To 0 Step -1
        If $aArr[$i] = "1" Then
           $dec = BitXOR($dec, BitShift(1, -(UBound($aArr) - 1 - $i)))
           $sOut=Hex($dec) &" "& $dec
        EndIf
    Next
Next

$t=TimerDiff($t)

ConsoleWrite("Based on code from: "& $sBasedOn & @CRLF& " Check: "& $sOut &" "& @CRLF &" "& $iIter &" Iterations in "& $t/1000  &" Seconds" &@CRLF&@CRLF)
Quote

Based on code from: JockoDundee
 Check: AA 170 
 1000000 Iterations in 3.4197433 Seconds
Based on code from: JockoDundee
 Check: AA 170 
 1000000 Iterations in 3.3934325 Seconds
Based on code from: JockoDundee
 Check: AA 170 
 1000000 Iterations in 3.4096929 Seconds

Local $sBasedOn="JockoDundee", $iIter=1000000, $sOut, $t=TimerInit()

Local $sbyte="10101010", $arr[1112]

$arr[0]="0"
$arr[1]="1"
$arr[10]="2"
$arr[11]="3"
$arr[100]="4"
$arr[101]="5"
$arr[110]="6"
$arr[111]="7"
$arr[1000]="8"
$arr[1001]="9"
$arr[1010]="A"
$arr[1011]="B"
$arr[1100]="C"
$arr[1101]="D"
$arr[1011]="E"
$arr[1111]="F"

For $n=1 To $iIter
   $sOut=$arr[StringLeft($sByte,4)] & $arr[StringRight($sByte,4)]
   $sOut=$sOut &" "& Dec($sOut)
Next

$t=TimerDiff($t)

ConsoleWrite("Based on code from: "& $sBasedOn & @CRLF& " Check: "& $sOut &" "& @CRLF &" "& $iIter &" Iterations in "& $t/1000  &" Seconds" &@CRLF&@CRLF)
Quote

Based on code from: Chimp
 Check: AA 170 
 1000000 Iterations in 3.9945812 Seconds
Based on code from: Chimp
 Check: AA 170 
 1000000 Iterations in 4.080412 Seconds
Based on code from: Chimp
 Check: AA 170 
 1000000 Iterations in 4.0526451 Seconds

Global $sBasedOn = "Chimp", $iIter = 1000000, $sOut, $t = TimerInit()
Global $sbyte = "10101010"

Global Enum $0000, $0001, $0010, $0011, $0100, $0101, $0110, $0111, $1000, $1001
Global $1010 = "A", $1011 = "B", $1100 = "C", $1101 = "D", $1110 = "E", $1111 = "F"

For $n = 1 To $iIter
    $sOut = Eval(StringLeft($sbyte, 4)) & Eval(StringRight($sbyte, 4))
    $sOut = $sOut & " " & Dec($sOut)
Next

$t = TimerDiff($t)

ConsoleWrite("Based on code from: " & $sBasedOn & @CRLF & " Check: " & $sOut & " " & @CRLF & " " & $iIter & " Iterations in " & $t / 1000 & " Seconds" & @CRLF & @CRLF)
Quote

Based on code from: Chimp with major_lee edit
 Check: AA 170 
 1000000 Iterations in 11.2108708 Seconds
Based on code from: Chimp with major_lee edit
 Check: AA 170 
 1000000 Iterations in 11.2885781 Seconds
Based on code from: Chimp with major_lee edit
 Check: AA 170 
 1000000 Iterations in 11.0158957 Seconds

Global $sBasedOn="Chimp with major_lee edit", $iIter = 1000000, $sOut, $t = TimerInit()

Global Enum $0000, $0001, $0010, $0011, $0100, $0101, $0110, $0111, $1000, $1001
Global Const $1010 = "A", $1011 = "B", $1100 = "C", $1101 = "D", $1110 = "E", $1111 = "F"
Global $dataStream = "10101010"


For $n = 1 To $iIter
    $sbyte = $dataStream
    $sOut = Null
    Local $bArray[StringLen ( $sbyte )/4+1]
    $bArray[0] = (StringLen ( $sbyte )/4)
    for $z = 1 To $bArray[0]
    $bArray[$z] = Eval(StringLeft($sbyte, 4))
    $sbyte = StringTrimLeft ( $sbyte, 4 )
    $sOut=$sOut&$bArray[$z]
    Next
    $sOut=$sOut &" "& Dec($sOut)
Next

$t = TimerDiff($t)
ConsoleWrite("Based on code from: "& $sBasedOn & @CRLF& " Check: "& $sOut &" "& @CRLF &" "& $iIter &" Iterations in "& $t/1000  &" Seconds" &@CRLF&@CRLF)

 

Edited by major_lee
benchmark for chimp typo, and jhcd $iIter
Link to comment
Share on other sites

I wanna play too:

Tester()
Func Tester()
    Local $t, $sResult, $sbyteOriginal="10101010"
    Local $o = ObjCreate("Scripting.Dictionary")
    $o.Add("0000", "0")
    $o.Add("0001", "1")
    $o.Add("0010", "2")
    $o.Add("0011", "3")
    $o.Add("0100", "4")
    $o.Add("0101", "5")
    $o.Add("0110", "6")
    $o.Add("0111", "7")
    $o.Add("1000", "8")
    $o.Add("1001", "9")
    $o.Add("1010", "A")
    $o.Add("1011", "B")
    $o.Add("1100", "C")
    $o.Add("1101", "D")
    $o.Add("1110", "E")
    $o.Add("1111", "F")

    $t = TimerInit()
    For $n = 1 To 1000 ; >>> 9.7685  -  $sResult: AA
        $sResult = ""
        $sbyte = $sbyteOriginal
        Do
            $sResult &= $o.Item(StringLeft($sbyte, 4))
            $sbyte = StringTrimLeft($sbyte, 4)
        Until $sbyte = ""
    Next
    ConsoleWrite(">>> " &TimerDiff($t)& "  -  $sResult: " &  $sResult & @CRLF)
EndFunc

And, I'd win 1st price for slowest original idea :P 

Edit: since I don't wanna lose to myself, here is a yet slower ones:

Spoiler
Tester()
Func Tester()
    Local $t, $sResult, $sbyteOriginal="10101010"
    $t = TimerInit()
    For $n = 1 To 1000 ; >>> 12.0355  -  $sResult: AA
        $sResult = ""
        $sbyte = $sbyteOriginal
        Do
            $sResult &= StrBin2Hex(StringLeft($sbyte, 4))
            $sbyte = StringTrimLeft($sbyte, 4)
        Until $sbyte = ""
    Next
    ConsoleWrite(">>> " &TimerDiff($t)& "  -  $sResult: " &  $sResult & @CRLF)
EndFunc

Func StrBin2Hex($sBin)
    Switch $sBin
        Case "0000"
            Return "0"
        Case "0001"
            Return "1"
        Case "0010"
            Return "2"
        Case "0011"
            Return "3"
        Case "0100"
            Return "4"
        Case "0101"
            Return "5"
        Case "0110"
            Return "6"
        Case "0111"
            Return "7"
        Case "1000"
            Return "8"
        Case "1001"
            Return "9"
        Case "1010"
            Return "A"
        Case "1011"
            Return "B"
        Case "1100"
            Return "C"
        Case "1101"
            Return "D"
        Case "1110"
            Return "E"
        Case "1111"
            Return "F"
    EndSwitch
EndFunc
Tester()
Func Tester()
    Local $t, $sResult, $sbyteOriginal="10101010"

    Local Const $tagSBINTHING = "struct;CHAR 0000;CHAR 0001;CHAR 0010;CHAR 0011;CHAR 0100;CHAR 0101;CHAR 0110;CHAR 0111;" & _
                                    "CHAR 1000;CHAR 1001;CHAR 1010;CHAR 1011;CHAR 1100;CHAR 1101;CHAR 1110;CHAR 1111;endstruct"
    Local $tSBINTHING = DllStructCreate($tagSBINTHING) ; ...GETTING FANCY HERE   ;)
    DllStructSetData($tSBINTHING, "0000", "0")
    DllStructSetData($tSBINTHING, "0001", "1")
    DllStructSetData($tSBINTHING, "0010", "2")
    DllStructSetData($tSBINTHING, "0011", "3")
    DllStructSetData($tSBINTHING, "0100", "4")
    DllStructSetData($tSBINTHING, "0101", "5")
    DllStructSetData($tSBINTHING, "0110", "6")
    DllStructSetData($tSBINTHING, "0111", "7")
    DllStructSetData($tSBINTHING, "1000", "8")
    DllStructSetData($tSBINTHING, "1001", "9")
    DllStructSetData($tSBINTHING, "1010", "A")
    DllStructSetData($tSBINTHING, "1011", "B")
    DllStructSetData($tSBINTHING, "1100", "C")
    DllStructSetData($tSBINTHING, "1101", "D")
    DllStructSetData($tSBINTHING, "1110", "E")
    DllStructSetData($tSBINTHING, "1111", "F")

    $t = TimerInit()
    For $n = 1 To 1000 ; >>> 10.1052  -  $sResult: AA
        $sResult = ""
        $sbyte = $sbyteOriginal
        Do
            $sResult &= DllStructGetData($tSBINTHING, StringLeft($sbyte, 4))
            $sbyte = StringTrimLeft($sbyte, 4)
        Until $sbyte = ""
    Next
    ConsoleWrite(">>> " &TimerDiff($t)& "  -  $sResult: " &  $sResult & @CRLF)
EndFunc

 

 

Edited by argumentum
am a sore loser/winner

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

8 hours ago, JockoDundee said:

 ... are you compiling 64-bit or 32-bit?  any other flags?

All flags in my AutoIt/SciTE version (3.3.14.0) are on default (e.g. x64=No).
If I set the directive #AutoIt3Wrapper_UseX64 = Y , then your variant is faster than Chimp's (as you stated) :).

Based on code from: Chimp
-> with #AutoIt3Wrapper_UseX64 = Y (Default=N)
==> Trial 1 : 1000000 Iterations in 4.46783944157985 Seconds
==> Trial 2 : 1000000 Iterations in 4.4102539416485 Seconds
==> Trial 3 : 1000000 Iterations in 4.39570894432897 Seconds

 

Based on code from: JockoDundee
-> with #AutoIt3Wrapper_UseX64 = Y (Default=N)
==> Trial 1 : 1000000 Iterations in 3.6696164912397 Seconds
==> Trial 2 : 1000000 Iterations in 3.7065374362568 Seconds
==> Trial 3 : 1000000 Iterations in 3.6125747123171 Seconds

4 hours ago, argumentum said:

I wanna play too:

Funny, I also tried it via a "Scripting.Dictionary Object" but it is, as you wrote, slow :lol:.

Spoiler
Local $sBasedOn = "Musashi : Dictionary", $iIter=1000000, $sOut, $t=TimerInit(), $oDictionary
Local $sbyte    = "10101010"

$oDictionary = ObjCreate("Scripting.Dictionary")
If @error Then
    Exit MsgBox(0, 'Message : ', 'Error creating the dictionary object')
Else
    $oDictionary.Add ("0000", "0")
    $oDictionary.Add ("0001", "1")
    $oDictionary.Add ("0010", "2")
    $oDictionary.Add ("0011", "3")
    $oDictionary.Add ("0100", "4")
    $oDictionary.Add ("0101", "5")
    $oDictionary.Add ("0110", "6")
    $oDictionary.Add ("0111", "7")
    $oDictionary.Add ("1000", "8")
    $oDictionary.Add ("1001", "9")
    $oDictionary.Add ("1010", "A")
    $oDictionary.Add ("1011", "B")
    $oDictionary.Add ("1100", "C")
    $oDictionary.Add ("1101", "D")
    $oDictionary.Add ("1110", "E")
    $oDictionary.Add ("1111", "F")
EndIf

For $n = 1 To $iIter
    $sOut = $oDictionary.Item(StringLeft($sByte,4)) & $oDictionary.Item(StringRight($sByte,4))
    $sOut = $sOut & " " & Dec($sOut)
Next
$t=TimerDiff($t)
ConsoleWrite("Based on code from: "& $sBasedOn & @CRLF& " Check: "& $sOut &" "& @CRLF &" "& $iIter &" Iterations in "& $t/1000  &" Seconds" & @CRLF & @CRLF)

 

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

13 hours ago, JockoDundee said:

@Chimp, did you see any performance difference between the two on your machine?

 

... your is a bit faster:

Based on code from: Chimp
 Check: AA 170
 100000 Iterations in 0.5807074 Seconds

Based on code from: JockoDundee
 Check: AA 170
 100000 Iterations in 0.5009863 Seconds

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

This is cool, cause I'm learning a lot, all the different ways it can be done. I've never even considered using COM objects.

 

Quote

Based on code from: argumentum
 Check: AA 170 
 1000000 Iterations in 10.8612472 Seconds
Based on code from: argumentum
 Check: AA 170 
 1000000 Iterations in 10.9447503 Seconds
Based on code from: argumentum
 Check: AA 170 
 1000000 Iterations in 10.5175166 Seconds

Local $sBasedOn="argumentum", $iIter=1000000, $t=TimerInit()
Local $sResult, $sbyteOriginal="10101010", $dec
Local $o = ObjCreate("Scripting.Dictionary")
    $o.Add("0000", "0")
    $o.Add("0001", "1")
    $o.Add("0010", "2")
    $o.Add("0011", "3")
    $o.Add("0100", "4")
    $o.Add("0101", "5")
    $o.Add("0110", "6")
    $o.Add("0111", "7")
    $o.Add("1000", "8")
    $o.Add("1001", "9")
    $o.Add("1010", "A")
    $o.Add("1011", "B")
    $o.Add("1100", "C")
    $o.Add("1101", "D")
    $o.Add("1110", "E")
    $o.Add("1111", "F")

For $n=1 To $iIter
        $sResult = ""
        $sbyte = $sbyteOriginal
        Do
            $sResult &= $o.Item(StringLeft($sbyte, 4))
            $sbyte = StringTrimLeft($sbyte, 4)
        Until $sbyte = ""
$sOut = $sResult &" "& Dec($sResult)
Next

$t=TimerDiff($t)

ConsoleWrite("Based on code from: "& $sBasedOn & @CRLF& " Check: "& $sOut &" "& @CRLF &" "& $iIter &" Iterations in "& $t/1000  &" Seconds" &@CRLF&@CRLF)

 

Link to comment
Share on other sites


I think its only fair to extend the code to handle more then the limited bytes as originally assumed.

 

Quote

Based on code from: JockoDundee with major_lee edit
 Check: AA 170 
 1000000 Iterations in 10.7270697 Seconds
Based on code from: JockoDundee with major_lee edit
 Check: AA 170 
 1000000 Iterations in 10.7771624 Seconds
Based on code from: JockoDundee with major_lee edit
 Check: AA 170 
 1000000 Iterations in 10.7246844 Seconds

 

Local $sBasedOn="JockoDundee with major_lee edit", $iIter=1000000, $sOut, $t=TimerInit()

Local $dataStream="10101010", $arr[1112]

$arr[0]="0"
$arr[1]="1"
$arr[10]="2"
$arr[11]="3"
$arr[100]="4"
$arr[101]="5"
$arr[110]="6"
$arr[111]="7"
$arr[1000]="8"
$arr[1001]="9"
$arr[1010]="A"
$arr[1011]="B"
$arr[1100]="C"
$arr[1101]="D"
$arr[1011]="E"
$arr[1111]="F"


For $n=1 To $iIter
    $sbyte = $dataStream
    $sOut = Null
    Local $bArray[StringLen ( $sbyte )/4+1]
    $bArray[0] = (StringLen ( $sbyte )/4)

    for $z = 1 To $bArray[0]
        $bArray[$z] = $arr[StringLeft($sbyte, 4)]
        $sbyte = StringTrimLeft ( $sbyte, 4 )
        $sOut=$sOut&$bArray[$z]
    Next
    $sOut=$sOut &" "& Dec($sOut)
Next

$t=TimerDiff($t)

ConsoleWrite("Based on code from: "& $sBasedOn & @CRLF& " Check: "& $sOut &" "& @CRLF &" "& $iIter &" Iterations in "& $t/1000  &" Seconds" &@CRLF&@CRLF)

 

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...