Jump to content

Recommended Posts

am632

Hi,

I have a binary string that I want to convert to octal, The string I want to convert is,

10001001010100000100111001000111000011010000101000011010

 

The String is read from a .txt file

Once its converted it should read this,

4   2   2   5   0   1   1   6   2   1   6   0   6   4   1   2   0   6   10

which I want written to the .txt file to overwrite the original binary string.

The 10 at the end should be ignored as there are not 3 digits to convert.

I'm thinking it should read the string from left to right to get the next 3 digits before converting them to its oct value. would this be the best way to do this or is there a better way?

If i'm on the right track can anyone give me an example of how to write this script please?

I've looked at the StringLeft function & StringReplace but I'm not sure how to use them the correct way to accomplish what I'm trying to do.

Thanks

 

Share this post


Link to post
Share on other sites
UEZ

Try this:

;coded by UEZ build 2016-05-06
Global $sBin = "10001001010100000100111001000111000011010000101000011010"

Global $sOctal = Convert_Bin_To_Oct(StringTrimRight($sBin, Mod(StringLen($sBin), 3)))
Global $sRest = StringRight($sBin, Mod(StringLen($sBin), 3))

MsgBox(0, "", $sOctal & ", " & $sRest)

Func Convert_Bin_To_Oct($sBin)
    $sBin = StringStripWS($sBin, 8)
    If StringRegExp($sBin, "[^0-1]", 0) Then Return SetError(1, 0, -1) ;not binary
    Local $aFillUp[3] = ["", "00", "0"], $i, $sOctal
    Local $aTokens = StringRegExp($aFillUp[Mod(StringLen($sBin), 3)] & $sBin, ".{3}", 3)
    For $i = 0 To UBound($aTokens) - 1
        $sOctal &= StringLeft($aTokens[$i], 1) * 2^2 + StringMid($aTokens[$i], 2, 1) * 2^1 + StringRight($aTokens[$i], 1) * 2^0 & " "
    Next
    Return $sOctal
EndFunc

 

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
VIP
56 minutes ago, UEZ said:

Try this:

Global $sBin = "10001001010100000100111001000111000011010000101000011011"

Global $sOctal = Convert_Bin_To_Oct($sBin)

MsgBox(0, "", $sOctal)

Func Convert_Bin_To_Oct($sBin)
    $sBin = StringStripWS($sBin, 8)
    If StringRegExp($sBin, "[^0-1]", 0) Then Return SetError(1, 0, -1) ;not binary
    Local $aFillUp[3] = ["", "00", "0"], $i, $j, $sOctal
    Local $aTokens = StringRegExp($aFillUp[Mod(StringLen($sBin), 3)] & $sBin, ".{3}", 3)
    For $i = 0 To UBound($aTokens) - 1
        $sOctal &= StringLeft($aTokens[$i], 1) * 2^2 + StringMid($aTokens[$i], 2, 1) * 2^1 + StringRight($aTokens[$i], 1) * 2^0 & " "
    Next
    Return $sOctal
EndFunc

 

 

@UEZ Your function gives a wrong result!


@am632 Try this:

Global $sBinary = "10001001010100000100111001000111000011010000101000011011" ;"10001001"

Global $sOctal = _BinaryToDec($sBinary)

ConsoleWrite($sBinary & " = " & $sOctal & @CRLF)
ConsoleWrite($sBinary & " ~ " & Int($sOctal) & @CRLF)

MsgBox(0, "Bin2Dec", $sBinary & @CRLF & " = " & $sOctal & @CRLF & " ~ " & Int($sOctal))

Func _BinaryToDec($sBinary)
    $sBinary = StringStripWS($sBinary, 8)
    Local $xOutput = 0, $intIndex
    If StringRegExp($sBinary, '[0-1]') Then
        For $intIndex = StringLen($sBinary) To 1 Step -1
            $strDigit = StringMid($sBinary, $intIndex, 1)
            Switch $strDigit
                Case 0
                    ContinueLoop
                Case 1
                    $xOutput = $xOutput + (2 ^ (StringLen($sBinary) - $intIndex))
                Case Else
                    ; invalid binary digit, so the whole thing is invalid
                    Return SetError(1, 0, "")
            EndSwitch
        Next
        Return $xOutput
    Else
        Return SetError(1, 0, "")
    EndIf
EndFunc   ;==>_BinaryToDec

 


Regards,
 

Share this post


Link to post
Share on other sites
jchd

Simpler, but with little conformal checking:

Global $sBin = "10001001010100000100111001000111000011010000101000011010"
Global $sOctal = Convert_Bin_To_Otc($sBin)
MsgBox(0, "", $sOctal)

Func Convert_Bin_To_Otc($sBin)
    Local $sBinOct = "000 001 010 011 100 101 110 111"
    Local $sOctal
    Local $aTokens = StringRegExp($sBin, "[01]{3}|[01]{1,2}$", 3)
    For $i = 0 To UBound($aTokens) - 1
        $sOctal &= (StringLen($aTokens[$i]) = 3 ? (StringInStr($sBinOct, $aTokens[$i]) - 1) / 4 : $aTokens[$i]) & " "
    Next
    Return StringTrimRight($sOctal, 1)
EndFunc

 


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
UEZ
10 hours ago, Trong said:

@UEZ Your function gives a wrong result!

Are you sure? ;)


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
RTFC

My three cents, without a lookup table:

Global $sBin = "10001001010100000100111001000111000011010000101000011011"
MsgBox(0, "Bin2Oct",_Bin2Oct($sBin))

Func _Bin2Oct($sBin)

    $sBin=StringStripWS($sBin,8)
    If StringRegExp($sBin,"[^0-1]",0) or Stringlen($sBin)=0 Then Return SetError(1,0,-1) ; not binary

    Local $oct,$sOctal=""
    For $cc=0 to Int(stringlen($sbin)/3)-1  ; clips trailing bits
        $oct=Number("0x" & stringmid($sbin,1+$cc*3,3))
        $sOctal&=BitShift($oct,6)+BitShift(BitAND(0x010,$oct),3)+BitAND(0x001,$oct)
    Next

    Return $sOctal
EndFunc

This discards any trailing bits,, which in my view should not be part of the conversion proper. The OP can append them with: 

_Bin2Oct($sBin) & StringRight($sBin,Mod(StringLen($sBin),3))

I would myself probably opt to prefix the bit string with leading zeroes in the function:

$sBin = StringLeft("00",Mod(StringLen(StringStripWS($sBin,8)),3)) & StringStripWS($sBin,8)

but that's not what the OP wanted.

Edited by RTFC

Share this post


Link to post
Share on other sites
VIP
15 hours ago, UEZ said:

Are you sure? ;)

No, i was wrong!

Binary:   10001001010100000100111001000111
HEX    :   89 50 4E 47
String:     ‰PNG

Edited by Trong

Regards,
 

Share this post


Link to post
Share on other sites
am632

Hi guys,

Thanks for all the examples, really appreciate it.

I'm favouring jchd's example for this as it doesn't display the comma before the 10, how would I be able to not have any spaces in the octal string though (I know there were spaces in my original post but this was just for clarity of reading soz)?

I'll be honest I really dont understand how the code works - I keep reading through it but I havent used some of these functions before so it's not obvious to me. Would it be possible to write a function to put it back to a binary string again? I would normally have a go myself first to at least try but I really don't get it right now.

Thanks for all the help.

am

Share this post


Link to post
Share on other sites
jchd

Just ask:

Global $sBin = "10001001010100000100111001000111000011010000101000011010"
Global $sOctal = Convert_Bin_To_Otc($sBin)
MsgBox(0, "", $sOctal)

Func Convert_Bin_To_Otc($sBin)
    Local $sBinOct = "000 001 010 011 100 101 110 111"
    Local $sOctal
    Local $aTokens = StringRegExp($sBin, "[01]{3}|[01]{1,2}$", 3)
    For $i = 0 To UBound($aTokens) - 1
        $sOctal &= StringLen($aTokens[$i]) = 3 ? (StringInStr($sBinOct, $aTokens[$i]) - 1) / 4 : $aTokens[$i]
    Next
    Return $sOctal
EndFunc

Just be aware that you don't have any way to determine if the last 1 or 2 digits in {0.1} are actual octal digit(s) or the remnant of the uncomplete string of binary digits.


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
am632

Hi,

Thanks for that, thats exactly what I wanted, I get what you're saying about the left over digits but it shouldn't matter for my needs, I assume the left over digits would also be ignored when converted back to binary or would this not be the case? I'm simply trying to shorten a particular string of characters which I can un-shorten later.

Would you be able to show me how i'd go about changing it back into its binary string value please?

Thanks a lot

am

Share this post


Link to post
Share on other sites
jchd

That won't work: if the input string length is not a multiple of 3, then the remaining digits need to be separated somehow, else they will be interpreted as octal. If it's just for shortening, why use octal? Larger bases wil shrink the data more efficiently.

Yet I wonder where the string of binary digits come from. This doesn't look efficient in the first place.


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
am632

ok, would it be possible to check if the string is devisable by 3 first and store any remaining characters in a variable before removing them?

The binary string in the example is not the whole string im using, just a shortend string for the sake of the example.

I know there are other bases that will shring the string more but I just want to stick to a base with numbers, and as far as im aware octal offeres the best solution for this.

Share this post


Link to post
Share on other sites
jchd

Isn't decimal a base with "numbers"?

If you want to stick with octal, then you can use a smart trick to store the 1 or 2 last digits in the same string and not heve them misinterpreted back: add 8 to the last digit or 88 to the value formed by the last 2 digits. When you read your "cooked octal" string any (last) digit > 7 will denote the remnant of initial binary. And all this within 0..9 without extra tax.


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
jchd

If you want to follw the last route, try this:

Global $sBin = "10001001010100000100111001000111000011010000101000011010"
Global $sOctal = _BinaryStringToOctalString($sBin)
MsgBox(0, "To octal", $sBin & @LF & $sOctal)
MsgBox(0, "From octal", $sBin & @LF & OctalStringToBinaryString($sOctal))

Func _BinaryStringToOctalString($sBin)
    Local $sBinOct = "000 001 010 011 100 101 110 111"
    Local $sOctal
    Local $aTokens = StringRegExp($sBin, "[01]{3}|[01]{1,2}$", 3)
    For $i = 0 To UBound($aTokens) - 1
        $sOctal &= StringLen($aTokens[$i]) = 3 ? (StringInStr($sBinOct, $aTokens[$i]) - 1) / 4 : $aTokens[$i] + 88
    Next
    Return $sOctal
EndFunc

Func OctalStringToBinaryString($sOctal)
    Local $sBinOct = "000001010011100101110111"
    Local $sBinary
    Local $aDigits = StringSplit($sOctal, '', 2)
    For $i = 0 To UBound($aDigits) - 1
        $sBinary &= $aDigits[$i] < '8' ? StringMid($sBinOct, 3 * $aDigits[$i] + 1, 3) : $aDigits[$i] - 8
    Next
    Return $sBinary
EndFunc

 


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
VIP

SPAM :P

@jchd you can create a function to convert text into binary and vice versa?

Global $sBin = "10001001010100000100111001000111"

MsgBox(0, "Bin2Str", "Binary IN: " & $sBin & @LF & "String OUT: ‰PNG")
MsgBox(0, "Str2Bin", "String IN: ‰PNG" & @LF & "Binary OUT: " & $sBin)

Func _BinaryToString($sBin)

EndFunc   ;==>_BinaryToString

Func _StringToBinary($sString)

EndFunc   ;==>_StringToBinary

 

Edited by Trong

Regards,
 

Share this post


Link to post
Share on other sites
am632
24 minutes ago, jchd said:

If you want to follw the last route, try this:

Global $sBin = "10001001010100000100111001000111000011010000101000011010"
Global $sOctal = _BinaryStringToOctalString($sBin)
MsgBox(0, "To octal", $sBin & @LF & $sOctal)
MsgBox(0, "From octal", $sBin & @LF & OctalStringToBinaryString($sOctal))

Func _BinaryStringToOctalString($sBin)
    Local $sBinOct = "000 001 010 011 100 101 110 111"
    Local $sOctal
    Local $aTokens = StringRegExp($sBin, "[01]{3}|[01]{1,2}$", 3)
    For $i = 0 To UBound($aTokens) - 1
        $sOctal &= StringLen($aTokens[$i]) = 3 ? (StringInStr($sBinOct, $aTokens[$i]) - 1) / 4 : $aTokens[$i] + 88
    Next
    Return $sOctal
EndFunc

Func OctalStringToBinaryString($sOctal)
    Local $sBinOct = "000001010011100101110111"
    Local $sBinary
    Local $aDigits = StringSplit($sOctal, '', 2)
    For $i = 0 To UBound($aDigits) - 1
        $sBinary &= $aDigits[$i] < '8' ? StringMid($sBinOct, 3 * $aDigits[$i] + 1, 3) : $aDigits[$i] - 8
    Next
    Return $sBinary
EndFunc

 

This seems to do the job perfectly, Thanks for all the help.

:)

Share this post


Link to post
Share on other sites
jchd
40 minutes ago, Trong said:

SPAM :P

@jchd you can create a function to convert text into binary and vice versa?

Global $sBin = "10001001010100000100111001000111000011010000101000011010"

MsgBox(0, "To octal", "Binary IN: " & $sBin & @LF & "String OUT: ?PNG")
MsgBox(0, "To octal", "String IN: ?PNG" & @LF & "Binary OUT: " & $sBin)

Func _BinaryToString($sBin)

EndFunc   ;==>_BinaryToString

Func _StringToBinary($sString)

EndFunc   ;==>_StringToBinary

 

The binary is wrong (at least in Windows Western codepage).

;1000 1001  0101 0000  0100 1110  0100 0111  0000 1101  0000 1010  0001 1010
; 8    9     5    0     4    E     4    7     0    D     0    A     1    A
;    ‰          P          N          G         CR         LF        SUB

Also remember that what you call text is, in AutoIt, Unicode as UTF16-LE (more precisely it's UCS2, but anyway).

Why are strings of binary digits so fashionable today? It that a new social media challenge or what?


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
VIP

In ASCII conversion table in my computer books: character, HEX and binary code.
Convert STRING to HEX is simple in AutoIt, but I could not find a function to convert binary to string and string to binary.

 I also do not understand why AutoIt called binary string is Hex: BinaryToString() and StringToBinary().

 Why does not the HexToString() and StringToHex()?

I was stupid again?


Regards,
 

Share this post


Link to post
Share on other sites
jchd

Simple: it's never useful to manipulate a string of ASCII 0s and 1s. The most compact representation low-level in common use is hexadecimal. A binary variant (= datatype) in AutoIt and every language I know of essentially means "series of bytes with no possible interpretation as text or number".

  • Like 1

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

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

  • Similar Content

    • nooneclose
      By nooneclose
      I need help turning this string "20180913221626" into a formatted time string.
      I need to go from this: 20180913221626
      to this: 09/13/2018 10:16 PM
      I do not always know what the date will be so I can not just use a variable I need to actually convert/format. 
      I did see an older post in the forms that was basically the same question only the other guy did not post the working code and I can not figure out how to use _AD_GetObjectProperties properly to get what I want. 
      As always any help would be appreciated. 
      Here is the code I use to find the date, but it always gives me the unformatted version. 
      ;retrieve the items object $oItem = $oOutlook.Session.GetItemFromID($aItems[1][0], Default) $oItem.GetInspector $eSentOn = $oItem.SentOn ; When was the email sent? MsgBox("", "Sent On of the email", $eSentOn) ;******************************************************************************* ; Formats the date and time from the email ;******************************************************************************* ;Local $fDatenTime = _DateTimeFormat($eSentOn, 1) ;MsgBox("", "Formatted email time", $fDatenTime) $aProperties = _AD_GetObjectProperties($eSentOn) _ArrayDisplay($aProperties, "Did the conversion work?")  
    • jtpr
      By jtpr
      Has anybody ever imported a VuGen recording into AutoIT?  I like the recording cabability of VuGen and thought it would be great to use and then pull it into AutoIT to compile into an EXE.
       
      Jim
    • FMS
      By FMS
      Hello,
      I'm trying to read a binary file to an array but couln't get it to work.
      Also I coul not find any help in the forum around this subject whish was helpfull.
      Is there any way it could be done?
      I tried a lot of ways but maybe somebody know's the right way?
      #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <File.au3> #include <Array.au3> #include <AutoItConstants.au3> Local $in=FileOpen("TEST_labels.idx1-ubyte",16) ; 16+0=Read binary Local $data = FileRead($in) Local $FileArray = BinaryToString($data,4) ;~ $FileArray = StringSplit($BinarydData, @CRLF, 1+2) ;~ Local $FileArray = StringRegExp($BinarydData, "[^\r\n]+", 3) FileClose($in) _ArrayDisplay($FileArray,"$FileArray","",32) MsgBox($MB_SYSTEMMODAL, "", "$FileArray = " & $FileArray )  
      TEST_labels.idx1-ubyte
    • Dragonfighter
      By Dragonfighter
      I'm searching a way to do xor and shift and if possible also other operations. Thanks in advance for the replies.
    • rudi
      By rudi
      Hello.
      I'm too stupid to see my mistake:
      To investigate the internal "dictionary" of TIFF files I'd like to read in the files in binary mode and to check, if there are more than one pages "in" this TIFF.
      Notepad++, "View as Hex" is presenting the first bytes as "49 49 2a 20 08 20 20 20 12" for the TIF attached to this posting
      The "TIFF Header Format" is easy:
      Offset 00h, 2 Byte = Byte Order, "II"=intel, "MM"=motorola. (I = 0x49)
      --> II
      Offset 02h, 2 Byte = Version Nr.
      Offset 04h, 4 Byte = pointer to first IFD entry
      Description of TIFF header: https://www.awaresystems.be/imaging/tiff/faq.html#q3
       

      Howto read and analyse the binary content correctly? This is my messy, not operational code:
       
      $sampleTiff="H:\daten\tif\11\11\111111.TIF" $h=FileOpen($sampleTiff,16) $content=FileRead($h) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $content = ' & $content & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console FileClose($h) $type=VarGetType($content) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $type = ' & $type & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $ToString=BinaryToString($content) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $ToString = ' & $ToString & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite(@CRLF & @CRLF) $content=StringTrimLeft($content,2) ; cut off the leading "0x" ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $content = ' & $content & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console for $i = 1 to 8 step 8 $next=StringMid($content,$i,2) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $next = ' & $next & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $Chr=BinaryToString($next) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Chr = ' & $Chr & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite(@CRLF & "---" & @CRLF) Next Regards, Rudi.
      111111.TIF
×