Sign in to follow this  
Followers 0
Inververs

read file to bytearray

12 posts in this topic

How to read binary file and create array of bytes?

Example: bytes string: 0xFD3EDFC4...

Need this array:

0|0xFD

1|0x3E

2|0xDF

3|0xC4

...

?

Share this post


Link to post
Share on other sites

#2 ·  Posted (edited)

Have you looked in the help file at the binary functions, such as BinaryToString, StringToBinary, etc?

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Is there binaryToArray?

Share this post


Link to post
Share on other sites

How about you crack the help file open and look ;)


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

No, there is no make of this, I looked course. There is only a function of conversion to a string, but I do not need a string, I need bytes.

Edited by Inververs

Share this post


Link to post
Share on other sites

So, you can't convert to a string and then do a StringSplit?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

JLogan3o13, I understand your approach. Thank you. But the theme is: how to get an array of bytes, rather than how to use certain functions binarytostring

Share this post


Link to post
Share on other sites

Want do you want/need to perform exactly? With an answer to this question it might be possible to guide you towards a simple and efficient solution ... or not.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I need For In iteration by byte in the binary data.

In the loop to get the first byte, then the second, then the third, etc.

Edited by Inververs

Share this post


Link to post
Share on other sites

I am sure someone will come along with a regex or something that works as well, but this works for me.

 

#include <Array.au3>
 
Local $aArray2[1] = [""]
$sBinary = "0xFD3EDFC4"
$aArray = StringSplit($sBinary, "")
 
For $i = 3 To $aArray[0] Step 2
  _ArrayAdd($aArray2, $aArray[1] & $aArray[2] & $aArray[$i] & $aArray[$i + 1])
Next
 
_ArrayDelete($aArray2, 0)
 _ArrayDisplay($aArray2)

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

sorry for my bad english 

this can be an alternative using a function that can also be useful for other examples
#Include <Array.au3>
$sBinary = "0xFD3EDFC4"
$count=2

$stringsplit_array=stringsplit_count($sBinary,$count) 

For $i = 1 To ubound($stringsplit_array)-1
  $stringsplit_array[$i]=$stringsplit_array[0]&$stringsplit_array[$i]
Next 
_ArrayDelete($stringsplit_array, 0)
_ArrayDisplay($stringsplit_array)

func stringsplit_count($string,$count)
    if $string="" Then
        return SetError(-1, 0, 0)
    else
        $stringlen=stringlen($string)
        $div=int($stringlen/$count)
        if $stringlen<>$count*$div then $div+=1
        dim $stringsplit_array[$div]
        for $i=0 to $div-1
            if $i=0 then
                $ii=1
            Else
                $ii+=$count
            EndIf
            $stringsplit_array[$i]=stringmid($string,$ii,$count)
        Next
        SetError(1, 0, 0)
        return $stringsplit_array
    endif
endfunc

Share this post


Link to post
Share on other sites

Inververs,

Perhaps this...

#Include <Array.au3>
$sBinary = "0xFD3EDFC4"

local $bArray = stringregexp($sBinary,'(?:0x)?(.{2})',3)

_arraydisplay($bArray)

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
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
Sign in to follow this  
Followers 0