CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
reading binary data and writing it as hex

 



talor
New User

Jun 24, 2009, 11:42 PM

Post #1 of 2 (381 views)
reading binary data and writing it as hex Can't Post

Hi,



I have a binary data file: 43 2F FF A2 2B 12 99 4C... (each pair represents a byte)

The user is supposed to give me a pattern: 0000_###_0 (each '#' represents a byte)

And I want to ouput:

0000_432fff_0

0000_a22b12_0

etc.

The pattern isn't fixed, so the number of '#' may change (though they have to be consecutive).

Let's say I already read the amount of bytes requestsed from the data file, is there a way to use 'unpack' to output such a hex number (which isn't the size of an int or long necessarily)?

BTW, I could do it by writing one byte at a time but the data files I'm dealing with are very big and I'm looking for a faster way to do it... (specifically to unpack into a variable and writing it with printf and %x).



Thanks a lot!


1arryb
User

Jun 25, 2009, 12:57 PM

Post #2 of 2 (374 views)
Re: [talor] reading binary data and writing it as hex [In reply to] Can't Post

Hi talor,

You can do pretty much whatever you want with pack and unpack. Why don't you read the manual on those functions, try a few things, and come back with some test code and your (more specific) questions?

Good luck,

Larry

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives