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
4
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
    4
    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
      4
      down vote

      favorite









      up vote
      4
      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 2 hours ago









      Attie

      10.1k32338




      10.1k32338






      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 2 hours ago









      DavOS

      1235




      1235




      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.




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          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
            1 hour ago










          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






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          3
          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
            1 hour ago














          up vote
          3
          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
            1 hour ago












          up vote
          3
          down vote



          accepted







          up vote
          3
          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 2 hours ago









          Attie

          10.1k32338




          10.1k32338











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
















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















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




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










          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













































































          Comments

          Popular posts from this blog

          What does second last employer means? [closed]

          Installing NextGIS Connect into QGIS 3?

          One-line joke