convert text file of bits to binary file

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
8
down vote

favorite












I have a file instructions.txt with the contents:



00000000000000000000000000010011
00000010110100010010000010000011
00000000011100110000001010110011
00000000011100110000010000110011
00000000011100110110010010110011
00000000000000000000000000010011


How can I create a binary file instructions.bin of the same data as instructions.txt. In other words the .bin file should be the same 192 bits that are in the .txt file, with 32 bits per line. I am using bash on Ubuntu Linux. I was trying to use xxd -b instructions.txt but the output is way longer than 192 bits.










share|improve this question









New contributor




DavOS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.























    up vote
    8
    down vote

    favorite












    I have a file instructions.txt with the contents:



    00000000000000000000000000010011
    00000010110100010010000010000011
    00000000011100110000001010110011
    00000000011100110000010000110011
    00000000011100110110010010110011
    00000000000000000000000000010011


    How can I create a binary file instructions.bin of the same data as instructions.txt. In other words the .bin file should be the same 192 bits that are in the .txt file, with 32 bits per line. I am using bash on Ubuntu Linux. I was trying to use xxd -b instructions.txt but the output is way longer than 192 bits.










    share|improve this question









    New contributor




    DavOS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      8
      down vote

      favorite









      up vote
      8
      down vote

      favorite











      I have a file instructions.txt with the contents:



      00000000000000000000000000010011
      00000010110100010010000010000011
      00000000011100110000001010110011
      00000000011100110000010000110011
      00000000011100110110010010110011
      00000000000000000000000000010011


      How can I create a binary file instructions.bin of the same data as instructions.txt. In other words the .bin file should be the same 192 bits that are in the .txt file, with 32 bits per line. I am using bash on Ubuntu Linux. I was trying to use xxd -b instructions.txt but the output is way longer than 192 bits.










      share|improve this question









      New contributor




      DavOS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I have a file instructions.txt with the contents:



      00000000000000000000000000010011
      00000010110100010010000010000011
      00000000011100110000001010110011
      00000000011100110000010000110011
      00000000011100110110010010110011
      00000000000000000000000000010011


      How can I create a binary file instructions.bin of the same data as instructions.txt. In other words the .bin file should be the same 192 bits that are in the .txt file, with 32 bits per line. I am using bash on Ubuntu Linux. I was trying to use xxd -b instructions.txt but the output is way longer than 192 bits.







      linux bash binary-files xxd






      share|improve this question









      New contributor




      DavOS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      DavOS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 10 hours ago









      Attie

      10.2k32338




      10.2k32338






      New contributor




      DavOS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 10 hours ago









      DavOS

      1435




      1435




      New contributor




      DavOS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      DavOS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      DavOS is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          6
          down vote



          accepted










          You were on the right track with xxd -b, but you need some other options too:




          • -p - use the "plain hexdump style"


          • -r - use the "reverse operation"

          Be careful, because xxd doesn't accept multiple options (e.g: -bpr) - they need to be given separately.



          $ cat instructions.txt
          00000000000000000000000000010011
          00000010110100010010000010000011
          00000000011100110000001010110011
          00000000011100110000010000110011
          00000000011100110110010010110011
          00000000000000000000000000010011
          $ xxd -b -p -r < instructions.txt > instructions.bin
          $ hexdump -Cv < instructions.bin
          00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 11 |................|
          00000010 00 00 00 10 11 01 00 01 00 10 00 00 10 00 00 11 |................|
          00000020 00 00 00 00 01 11 00 11 00 00 00 10 10 11 00 11 |................|
          00000030 00 00 00 00 01 11 00 11 00 00 01 00 00 11 00 11 |................|
          00000040 00 00 00 00 01 11 00 11 01 10 01 00 10 11 00 11 |................|
          00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 11 |................|
          00000060





          share|improve this answer




















          • Thank you so so much you are awesome! This is exactly what I was looking for!
            – DavOS
            9 hours ago






          • 1




            Careful - this reads 0 and 1 as hex digits, not as bits. From xxd's manpage about the -b flag: "The command line switches -r, -p, -i do not work with this mode."
            – nomadictype
            3 hours ago

















          up vote
          0
          down vote













          Adding the -r option (reverse mode) to xxd -b does not actually work as intended, because xxd simply does not support combining these two flags (it ignores -b if both are given). Instead, you have to convert the bits to hex yourself first. For example like this:



          ( echo 'obase=16;ibase=2'; sed -Ee 's/[01]4/;/g' instructions.txt ) | bc | xxd -r -p > instructions.bin


          Full explanation:



          • The part inside the parentheses creates a bc script. It first sets the input base to binary (2) and the output base to hexadecimal (16). After that, the sed command prints the contents of instructions.txt with a semicolon between each group of 4 bits, which corresponds to 1 hex digit. The result is piped into bc.

          • The semicolon is a command separator in bc, so all the script does is print every input integer back out (after base conversion).

          • The output of bc is a sequence of hex digits, which can be converted to a file with the usual xxd -r -p.

          Output:



          $ hexdump -Cv instructions.bin
          00000000 00 00 00 13 02 d1 20 83 00 73 02 b3 00 73 04 33 |...... ..s...s.3|
          00000010 00 73 64 b3 00 00 00 13 |.sd.....|
          00000018
          $ xxd -b -c4 instructions.bin
          00000000: 00000000 00000000 00000000 00010011 ....
          00000004: 00000010 11010001 00100000 10000011 .. .
          00000008: 00000000 01110011 00000010 10110011 .s..
          0000000c: 00000000 01110011 00000100 00110011 .s.3
          00000010: 00000000 01110011 01100100 10110011 .sd.
          00000014: 00000000 00000000 00000000 00010011 ....





          share|improve this answer










          New contributor




          nomadictype is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.

















          • Sorry, there's still an endianness bug in this. Working on fixing it!
            – nomadictype
            2 hours ago










          • Actually, it's fine. I was confused earlier by using the wrong output width in the last xxd command.
            – nomadictype
            2 hours ago

















          up vote
          0
          down vote













          oneliner to convert 32-bit strings of ones and zeros into corresponding binary:



          $ perl -ne 'print pack("B32", $_)' < instructions.txt > instructions.bin


          verify:



          $ hexdump -Cv instructions.bin
          00000000 00 00 00 13 02 d1 20 83 00 73 02 b3 00 73 04 33 |...... ..s...s.3|
          00000010 00 73 64 b3 00 00 00 13 |.sd.....|
          00000018





          share|improve this answer




















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "3"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );






            DavOS is a new contributor. Be nice, and check out our Code of Conduct.









             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1365264%2fconvert-text-file-of-bits-to-binary-file%23new-answer', 'question_page');

            );

            Post as a guest






























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            6
            down vote



            accepted










            You were on the right track with xxd -b, but you need some other options too:




            • -p - use the "plain hexdump style"


            • -r - use the "reverse operation"

            Be careful, because xxd doesn't accept multiple options (e.g: -bpr) - they need to be given separately.



            $ cat instructions.txt
            00000000000000000000000000010011
            00000010110100010010000010000011
            00000000011100110000001010110011
            00000000011100110000010000110011
            00000000011100110110010010110011
            00000000000000000000000000010011
            $ xxd -b -p -r < instructions.txt > instructions.bin
            $ hexdump -Cv < instructions.bin
            00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 11 |................|
            00000010 00 00 00 10 11 01 00 01 00 10 00 00 10 00 00 11 |................|
            00000020 00 00 00 00 01 11 00 11 00 00 00 10 10 11 00 11 |................|
            00000030 00 00 00 00 01 11 00 11 00 00 01 00 00 11 00 11 |................|
            00000040 00 00 00 00 01 11 00 11 01 10 01 00 10 11 00 11 |................|
            00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 11 |................|
            00000060





            share|improve this answer




















            • Thank you so so much you are awesome! This is exactly what I was looking for!
              – DavOS
              9 hours ago






            • 1




              Careful - this reads 0 and 1 as hex digits, not as bits. From xxd's manpage about the -b flag: "The command line switches -r, -p, -i do not work with this mode."
              – nomadictype
              3 hours ago














            up vote
            6
            down vote



            accepted










            You were on the right track with xxd -b, but you need some other options too:




            • -p - use the "plain hexdump style"


            • -r - use the "reverse operation"

            Be careful, because xxd doesn't accept multiple options (e.g: -bpr) - they need to be given separately.



            $ cat instructions.txt
            00000000000000000000000000010011
            00000010110100010010000010000011
            00000000011100110000001010110011
            00000000011100110000010000110011
            00000000011100110110010010110011
            00000000000000000000000000010011
            $ xxd -b -p -r < instructions.txt > instructions.bin
            $ hexdump -Cv < instructions.bin
            00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 11 |................|
            00000010 00 00 00 10 11 01 00 01 00 10 00 00 10 00 00 11 |................|
            00000020 00 00 00 00 01 11 00 11 00 00 00 10 10 11 00 11 |................|
            00000030 00 00 00 00 01 11 00 11 00 00 01 00 00 11 00 11 |................|
            00000040 00 00 00 00 01 11 00 11 01 10 01 00 10 11 00 11 |................|
            00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 11 |................|
            00000060





            share|improve this answer




















            • Thank you so so much you are awesome! This is exactly what I was looking for!
              – DavOS
              9 hours ago






            • 1




              Careful - this reads 0 and 1 as hex digits, not as bits. From xxd's manpage about the -b flag: "The command line switches -r, -p, -i do not work with this mode."
              – nomadictype
              3 hours ago












            up vote
            6
            down vote



            accepted







            up vote
            6
            down vote



            accepted






            You were on the right track with xxd -b, but you need some other options too:




            • -p - use the "plain hexdump style"


            • -r - use the "reverse operation"

            Be careful, because xxd doesn't accept multiple options (e.g: -bpr) - they need to be given separately.



            $ cat instructions.txt
            00000000000000000000000000010011
            00000010110100010010000010000011
            00000000011100110000001010110011
            00000000011100110000010000110011
            00000000011100110110010010110011
            00000000000000000000000000010011
            $ xxd -b -p -r < instructions.txt > instructions.bin
            $ hexdump -Cv < instructions.bin
            00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 11 |................|
            00000010 00 00 00 10 11 01 00 01 00 10 00 00 10 00 00 11 |................|
            00000020 00 00 00 00 01 11 00 11 00 00 00 10 10 11 00 11 |................|
            00000030 00 00 00 00 01 11 00 11 00 00 01 00 00 11 00 11 |................|
            00000040 00 00 00 00 01 11 00 11 01 10 01 00 10 11 00 11 |................|
            00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 11 |................|
            00000060





            share|improve this answer












            You were on the right track with xxd -b, but you need some other options too:




            • -p - use the "plain hexdump style"


            • -r - use the "reverse operation"

            Be careful, because xxd doesn't accept multiple options (e.g: -bpr) - they need to be given separately.



            $ cat instructions.txt
            00000000000000000000000000010011
            00000010110100010010000010000011
            00000000011100110000001010110011
            00000000011100110000010000110011
            00000000011100110110010010110011
            00000000000000000000000000010011
            $ xxd -b -p -r < instructions.txt > instructions.bin
            $ hexdump -Cv < instructions.bin
            00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 11 |................|
            00000010 00 00 00 10 11 01 00 01 00 10 00 00 10 00 00 11 |................|
            00000020 00 00 00 00 01 11 00 11 00 00 00 10 10 11 00 11 |................|
            00000030 00 00 00 00 01 11 00 11 00 00 01 00 00 11 00 11 |................|
            00000040 00 00 00 00 01 11 00 11 01 10 01 00 10 11 00 11 |................|
            00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 11 |................|
            00000060






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 9 hours ago









            Attie

            10.2k32338




            10.2k32338











            • Thank you so so much you are awesome! This is exactly what I was looking for!
              – DavOS
              9 hours ago






            • 1




              Careful - this reads 0 and 1 as hex digits, not as bits. From xxd's manpage about the -b flag: "The command line switches -r, -p, -i do not work with this mode."
              – nomadictype
              3 hours ago
















            • Thank you so so much you are awesome! This is exactly what I was looking for!
              – DavOS
              9 hours ago






            • 1




              Careful - this reads 0 and 1 as hex digits, not as bits. From xxd's manpage about the -b flag: "The command line switches -r, -p, -i do not work with this mode."
              – nomadictype
              3 hours ago















            Thank you so so much you are awesome! This is exactly what I was looking for!
            – DavOS
            9 hours ago




            Thank you so so much you are awesome! This is exactly what I was looking for!
            – DavOS
            9 hours ago




            1




            1




            Careful - this reads 0 and 1 as hex digits, not as bits. From xxd's manpage about the -b flag: "The command line switches -r, -p, -i do not work with this mode."
            – nomadictype
            3 hours ago




            Careful - this reads 0 and 1 as hex digits, not as bits. From xxd's manpage about the -b flag: "The command line switches -r, -p, -i do not work with this mode."
            – nomadictype
            3 hours ago












            up vote
            0
            down vote













            Adding the -r option (reverse mode) to xxd -b does not actually work as intended, because xxd simply does not support combining these two flags (it ignores -b if both are given). Instead, you have to convert the bits to hex yourself first. For example like this:



            ( echo 'obase=16;ibase=2'; sed -Ee 's/[01]4/;/g' instructions.txt ) | bc | xxd -r -p > instructions.bin


            Full explanation:



            • The part inside the parentheses creates a bc script. It first sets the input base to binary (2) and the output base to hexadecimal (16). After that, the sed command prints the contents of instructions.txt with a semicolon between each group of 4 bits, which corresponds to 1 hex digit. The result is piped into bc.

            • The semicolon is a command separator in bc, so all the script does is print every input integer back out (after base conversion).

            • The output of bc is a sequence of hex digits, which can be converted to a file with the usual xxd -r -p.

            Output:



            $ hexdump -Cv instructions.bin
            00000000 00 00 00 13 02 d1 20 83 00 73 02 b3 00 73 04 33 |...... ..s...s.3|
            00000010 00 73 64 b3 00 00 00 13 |.sd.....|
            00000018
            $ xxd -b -c4 instructions.bin
            00000000: 00000000 00000000 00000000 00010011 ....
            00000004: 00000010 11010001 00100000 10000011 .. .
            00000008: 00000000 01110011 00000010 10110011 .s..
            0000000c: 00000000 01110011 00000100 00110011 .s.3
            00000010: 00000000 01110011 01100100 10110011 .sd.
            00000014: 00000000 00000000 00000000 00010011 ....





            share|improve this answer










            New contributor




            nomadictype is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.

















            • Sorry, there's still an endianness bug in this. Working on fixing it!
              – nomadictype
              2 hours ago










            • Actually, it's fine. I was confused earlier by using the wrong output width in the last xxd command.
              – nomadictype
              2 hours ago














            up vote
            0
            down vote













            Adding the -r option (reverse mode) to xxd -b does not actually work as intended, because xxd simply does not support combining these two flags (it ignores -b if both are given). Instead, you have to convert the bits to hex yourself first. For example like this:



            ( echo 'obase=16;ibase=2'; sed -Ee 's/[01]4/;/g' instructions.txt ) | bc | xxd -r -p > instructions.bin


            Full explanation:



            • The part inside the parentheses creates a bc script. It first sets the input base to binary (2) and the output base to hexadecimal (16). After that, the sed command prints the contents of instructions.txt with a semicolon between each group of 4 bits, which corresponds to 1 hex digit. The result is piped into bc.

            • The semicolon is a command separator in bc, so all the script does is print every input integer back out (after base conversion).

            • The output of bc is a sequence of hex digits, which can be converted to a file with the usual xxd -r -p.

            Output:



            $ hexdump -Cv instructions.bin
            00000000 00 00 00 13 02 d1 20 83 00 73 02 b3 00 73 04 33 |...... ..s...s.3|
            00000010 00 73 64 b3 00 00 00 13 |.sd.....|
            00000018
            $ xxd -b -c4 instructions.bin
            00000000: 00000000 00000000 00000000 00010011 ....
            00000004: 00000010 11010001 00100000 10000011 .. .
            00000008: 00000000 01110011 00000010 10110011 .s..
            0000000c: 00000000 01110011 00000100 00110011 .s.3
            00000010: 00000000 01110011 01100100 10110011 .sd.
            00000014: 00000000 00000000 00000000 00010011 ....





            share|improve this answer










            New contributor




            nomadictype is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.

















            • Sorry, there's still an endianness bug in this. Working on fixing it!
              – nomadictype
              2 hours ago










            • Actually, it's fine. I was confused earlier by using the wrong output width in the last xxd command.
              – nomadictype
              2 hours ago












            up vote
            0
            down vote










            up vote
            0
            down vote









            Adding the -r option (reverse mode) to xxd -b does not actually work as intended, because xxd simply does not support combining these two flags (it ignores -b if both are given). Instead, you have to convert the bits to hex yourself first. For example like this:



            ( echo 'obase=16;ibase=2'; sed -Ee 's/[01]4/;/g' instructions.txt ) | bc | xxd -r -p > instructions.bin


            Full explanation:



            • The part inside the parentheses creates a bc script. It first sets the input base to binary (2) and the output base to hexadecimal (16). After that, the sed command prints the contents of instructions.txt with a semicolon between each group of 4 bits, which corresponds to 1 hex digit. The result is piped into bc.

            • The semicolon is a command separator in bc, so all the script does is print every input integer back out (after base conversion).

            • The output of bc is a sequence of hex digits, which can be converted to a file with the usual xxd -r -p.

            Output:



            $ hexdump -Cv instructions.bin
            00000000 00 00 00 13 02 d1 20 83 00 73 02 b3 00 73 04 33 |...... ..s...s.3|
            00000010 00 73 64 b3 00 00 00 13 |.sd.....|
            00000018
            $ xxd -b -c4 instructions.bin
            00000000: 00000000 00000000 00000000 00010011 ....
            00000004: 00000010 11010001 00100000 10000011 .. .
            00000008: 00000000 01110011 00000010 10110011 .s..
            0000000c: 00000000 01110011 00000100 00110011 .s.3
            00000010: 00000000 01110011 01100100 10110011 .sd.
            00000014: 00000000 00000000 00000000 00010011 ....





            share|improve this answer










            New contributor




            nomadictype is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.









            Adding the -r option (reverse mode) to xxd -b does not actually work as intended, because xxd simply does not support combining these two flags (it ignores -b if both are given). Instead, you have to convert the bits to hex yourself first. For example like this:



            ( echo 'obase=16;ibase=2'; sed -Ee 's/[01]4/;/g' instructions.txt ) | bc | xxd -r -p > instructions.bin


            Full explanation:



            • The part inside the parentheses creates a bc script. It first sets the input base to binary (2) and the output base to hexadecimal (16). After that, the sed command prints the contents of instructions.txt with a semicolon between each group of 4 bits, which corresponds to 1 hex digit. The result is piped into bc.

            • The semicolon is a command separator in bc, so all the script does is print every input integer back out (after base conversion).

            • The output of bc is a sequence of hex digits, which can be converted to a file with the usual xxd -r -p.

            Output:



            $ hexdump -Cv instructions.bin
            00000000 00 00 00 13 02 d1 20 83 00 73 02 b3 00 73 04 33 |...... ..s...s.3|
            00000010 00 73 64 b3 00 00 00 13 |.sd.....|
            00000018
            $ xxd -b -c4 instructions.bin
            00000000: 00000000 00000000 00000000 00010011 ....
            00000004: 00000010 11010001 00100000 10000011 .. .
            00000008: 00000000 01110011 00000010 10110011 .s..
            0000000c: 00000000 01110011 00000100 00110011 .s.3
            00000010: 00000000 01110011 01100100 10110011 .sd.
            00000014: 00000000 00000000 00000000 00010011 ....






            share|improve this answer










            New contributor




            nomadictype is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.









            share|improve this answer



            share|improve this answer








            edited 2 hours ago





















            New contributor




            nomadictype is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.









            answered 2 hours ago









            nomadictype

            1012




            1012




            New contributor




            nomadictype is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.





            New contributor





            nomadictype is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.






            nomadictype is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.











            • Sorry, there's still an endianness bug in this. Working on fixing it!
              – nomadictype
              2 hours ago










            • Actually, it's fine. I was confused earlier by using the wrong output width in the last xxd command.
              – nomadictype
              2 hours ago
















            • Sorry, there's still an endianness bug in this. Working on fixing it!
              – nomadictype
              2 hours ago










            • Actually, it's fine. I was confused earlier by using the wrong output width in the last xxd command.
              – nomadictype
              2 hours ago















            Sorry, there's still an endianness bug in this. Working on fixing it!
            – nomadictype
            2 hours ago




            Sorry, there's still an endianness bug in this. Working on fixing it!
            – nomadictype
            2 hours ago












            Actually, it's fine. I was confused earlier by using the wrong output width in the last xxd command.
            – nomadictype
            2 hours ago




            Actually, it's fine. I was confused earlier by using the wrong output width in the last xxd command.
            – nomadictype
            2 hours ago










            up vote
            0
            down vote













            oneliner to convert 32-bit strings of ones and zeros into corresponding binary:



            $ perl -ne 'print pack("B32", $_)' < instructions.txt > instructions.bin


            verify:



            $ hexdump -Cv instructions.bin
            00000000 00 00 00 13 02 d1 20 83 00 73 02 b3 00 73 04 33 |...... ..s...s.3|
            00000010 00 73 64 b3 00 00 00 13 |.sd.....|
            00000018





            share|improve this answer
























              up vote
              0
              down vote













              oneliner to convert 32-bit strings of ones and zeros into corresponding binary:



              $ perl -ne 'print pack("B32", $_)' < instructions.txt > instructions.bin


              verify:



              $ hexdump -Cv instructions.bin
              00000000 00 00 00 13 02 d1 20 83 00 73 02 b3 00 73 04 33 |...... ..s...s.3|
              00000010 00 73 64 b3 00 00 00 13 |.sd.....|
              00000018





              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                oneliner to convert 32-bit strings of ones and zeros into corresponding binary:



                $ perl -ne 'print pack("B32", $_)' < instructions.txt > instructions.bin


                verify:



                $ hexdump -Cv instructions.bin
                00000000 00 00 00 13 02 d1 20 83 00 73 02 b3 00 73 04 33 |...... ..s...s.3|
                00000010 00 73 64 b3 00 00 00 13 |.sd.....|
                00000018





                share|improve this answer












                oneliner to convert 32-bit strings of ones and zeros into corresponding binary:



                $ perl -ne 'print pack("B32", $_)' < instructions.txt > instructions.bin


                verify:



                $ hexdump -Cv instructions.bin
                00000000 00 00 00 13 02 d1 20 83 00 73 02 b3 00 73 04 33 |...... ..s...s.3|
                00000010 00 73 64 b3 00 00 00 13 |.sd.....|
                00000018






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 1 hour ago









                Matija Nalis

                1,514716




                1,514716




















                    DavOS is a new contributor. Be nice, and check out our Code of Conduct.









                     

                    draft saved


                    draft discarded


















                    DavOS is a new contributor. Be nice, and check out our Code of Conduct.












                    DavOS is a new contributor. Be nice, and check out our Code of Conduct.











                    DavOS is a new contributor. Be nice, and check out our Code of Conduct.













                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1365264%2fconvert-text-file-of-bits-to-binary-file%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?