Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Working with binary data

 [1/8] from: jr:brainbyte at: 26-Sep-2000 17:40


If I read in a binary file I get this for example: variable: #{ 524946462400000043444441666D742018000000010001005C774C0100000000 B253000000020000332D0400 } How do I navigate this to get to specific values and extract them and store them in variables? The best I could do is use data: first variable BUT, I would like to be able to extract more than one at a time. Thanks, Jeff

 [2/8] from: al:bri:xtra at: 27-Sep-2000 13:24


> If I read in a binary file I get this for example: > > variable: #{ > 524946462400000043444441666D742018000000010001005C774C0100000000 > B253000000020000332D0400 > } > > How do I navigate this to get to specific values and extract them and
store them in variables?
> The best I could do is use > data: first variable > > BUT, I would like to be able to extract more than one at a time. >> variable: #{
{ 524946462400000043444441666D742018000000010001005C774C0100000000 { B253000000020000332D0400 { } == #{ 524946462400000043444441666D742018000000010001005C774C0100000000 B253000000020000332D0400 }
>> at variable 2
== #{ 4946462400000043444441666D742018000000010001005C774C0100000000B2 53000000020000332D0400 }
>> first at variable 2
== 73
>> first at variable 3
== 70
>> first at variable 4
== 70
>> first at variable 1
== 82
>> foreach byte variable [print byte]
82 73 70 70 36 0 0 0 67 68 68 65 102 109 116 32 24 0 0 0 1 0 1 0 92 119 76 1 0 0 0 0 178 83 0 0 0 2 0 0 51 45 4 0
>> >> print copy/part at variable 12 5
#{41666D7420} I hope that helps. Andrew Martin ICQ: 26227169 http://members.nbci.com/AndrewMartin/ http://members.xoom.com/AndrewMartin/

 [3/8] from: jsc::dataheaven::de at: 27-Sep-2000 3:33


On Wed, 27 Sep 2000, you wrote:
> If I read in a binary file I get this for example: > variable: #{
<<quoted lines omitted: 3>>
> How do I navigate this to get to specific values and extract them and store > them in variables?
To move forward in the binary block use skip to walk over the bytes. To cut out a part of the binary-block use copy/part e.g choose 4 bytes from byte position 3 (counted from 1 as it is common in REBOL) in above block: result: copy/part skip variable 2 4 == #{46462400} If you want you can write a funciton to make it easier e.g: cut: func [seq pos len] [ copy/part skip seq (pos - 1) len ] So you can write the above example as: cut variable 3 4 Regards Jochen

 [4/8] from: tim:johnsons-web at: 26-Sep-2000 18:00


Hi Jeff: Try playing with the following code: ;=============================================================== variable: #{ 524946462400000043444441666D742018000000010001005C774C0100000000 B253000000020000332D0400 } print reform["first four bytes:" copy/part variable 4] variable: skip variable 4 print reform["next four bytes:" copy/part variable 4] print to-integer copy/part variable 4 ;=============================================================== And of course, you can assign copy/part variable 4 to another word and convert it into an integer:
>> second-integer: to-integer copy/part variable 4
== 603979776 I hope this helps... Tim [jr--brainbyte--com] wrote:

 [5/8] from: brett:codeconscious at: 27-Sep-2000 15:13



 [6/8] from: brett:codeconscious at: 27-Sep-2000 15:31


Sorry about the my last post, an unwanted extra mouse click - damned GUIs :) Just wanted to say, This link may be of use as well http://www.codeconscious.com/rebol/tips-and-techniques.html#EnbaseandDebase

 [7/8] from: chaz:innocent at: 26-Sep-2000 22:58


Great thread! Binary is cool! chaz REBOL[] print enbase/64 #{26EB2D027A2D85EAFE44404E2FE1DA7247AB} ask [] At 06:00 PM 9/26/00 -0800, you wrote:

 [8/8] from: jr:brainbyte at: 27-Sep-2000 0:34


Hehehe Cooool! Thanks for all the assistance, there is a definate lack of certain kinds of info online for Rebol dev. Next up... CD Ripping and Audio File Conversion in Rebol Hmm sounds like a job for Command...there goes more money. Jeff At 10:58 PM 9/26/2000 -0700, you wrote:

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted