Solved

Seeking help in File program

Posted on 2003-12-09
5
150 Views
Last Modified: 2010-03-04
Hi,

There is a file which contains a few lines. Each line has a hexadecimal number eg: abcdef12
Create a new file by swapping the data in bytes as: 12efcdab
How do I do this. Are there any inbuilt functions to implement this

Thanks
Kunal
0
Comment
Question by:Kunal_Sathe
  • 3
5 Comments
 
LVL 20

Accepted Solution

by:
jmcg earned 63 total points
ID: 9908303
If this is a homework problem, please show us some of your work and we may be able to help you.

If it's not a homework problem, please give some more context for why you want to do this. There may be a better approach before the data is written to the file in the wrong order.
0
 
LVL 20

Expert Comment

by:jmcg
ID: 9909981
One way to effect the byte reordering is:

s/(..)(..)(..)(..)/$4$3$2$1/;
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 62 total points
ID: 9910391
Another way is to use pack/unpack and reverse
0
 
LVL 20

Expert Comment

by:jmcg
ID: 10218563
Nothing has happened on this question in more than 7 weeks. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
split points between jmcg and ozo.

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question