Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1013551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:07:07+00:00 2026-05-16T10:07:07+00:00

this might be quite a newbie question, but i need to process a certain

  • 0

this might be quite a newbie question, but i need to process a certain text file and dump its content into a binary file and i do not know how – i decided to use perl, but my perl skills are quite low. I probably should have written this in C++, but this seem like a nice and easy task for perl, so why not learn something new? 😉 The text file has thousands of lines in this format:

2A02FC42 4

You can look at it as a hexadecimal number (the length is ALWAYS 8) and a regular number. Now i need to dump all the lines into a binary file in this format (it should look like this when viewed with a hex editor):

42FC022A00000004

More examples so it is clear:

70726F67 36 -> 676F727000000024
6A656374 471 -> 7463656A000001D7

The part of parsing the input file is easy, but i’m stuck on the second part, where i should write this into a binary file. I have no idea how to format the data in this way or even how to output things in binary mode. Can someone help me out here?

Thanks.

EDIT: updated the examples, forgot about endiannes – im on a LE system.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:07:08+00:00Added an answer on May 16, 2026 at 10:07 am

    Use pack:

    #! /usr/bin/perl
    
    use warnings;
    use strict;
    
    # demo only    
    *ARGV = *DATA;
    
    while (<>) {
      my($a,$b) = split;
      $a = join "", reverse $a =~ /(..)/g;
      $b = sprintf "%08x", $b;
    
      print pack "H*" => $a . $b;
    }
    
    __DATA__
    2A02FC42 4
    70726F67 36
    6A656374 471
    

    Sample run:

    $ ./prog.pl | od -t x1
    0000000 42 fc 02 2a 00 00 00 04 67 6f 72 70 00 00 00 24
    0000020 74 63 65 6a 00 00 01 d7
    0000030
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might be quite a trivial question, but which of these methods is best
This might be quite a strange question since usually people bind only complex types
This might seem like a ridiculous question since I'm quite inexperienced in .NET. Is
This might seem like a stupid question I admit. But I'm in a small
This might be a bit on the silly side of things but I need
This might be an interesting question. I need to test that if I can
This might sound like a little bit of a crazy question, but how can
This might be an odd question, but when I scale my image in C#
This might be a stupid question but if there's a better or proper way
I'm sure this might be quite common query but couldn't find good answer as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.