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 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

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 1575
Alex Hales
  • 0
Alex HalesTeacher
Asked: May 30, 20222022-05-30T20:25:52+00:00 2022-05-30T20:25:52+00:00

c – Modify a binary text by adding bits (Linux)

  • 0

[ad_1]

For days I have been stuck on this problem: I have an input.bin file and in another output.bin file I want to write every single character of the first file but with the addition of the bit 1111 before and after each of them so that when I give bash od -t x1, will be shown each character with the letter f before and after.

Content of input.bin:

0G;#%?M]BR=`Q&E}P.>Q\,- RUG}"XGFE
M6ZTSAH'OI]L":NW^O\K9~BUI58_J0;,S@
HEE}{!J6&ZV'YESUZZD"^'(XTU<N}SDL-MOCR{YCYOA7&-2NLTW$5QY*
J#KHLUL]T>M/2KDWR,>HHV|ZK6XX1 ~=SKF>52<M#U3T,
``V#>ER>BJYDO%2LG-HH]3UX=FE0VTS]B*2S6[~96<-2Y3I"
"O[F:6&EB)'R0\_GHU,7JABT,J-^-XTFQ3
>FK"UHLSVH0|N-0$X K)<1^DPH2|>ZG(CA&6[RHHEQ[#8
T,$^.B%ZQC`]6OJ.)I&A(_K1UL\`"{
5$(6O1;PIZL8_H3$6LGU`_O)X,7"AXFM2M$E+CT]0 H}IZE3D0.GX#V
+?]Z},HP.GQ:KW\N(EI$42%C1NFEB >_CTESBJ'PV3<HRE0Z`70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ZN$KY]{MY=BR'CASQIV?~XN%J+~GPZV"AB!EUI}AZEB&B^
DF7?{N)NC:GB$-R\UQC$"LBDELVN\DLPQ,^;X` O/

Content of input.bin if I read it doing od -t x1 input.bin from bash:

0000000 30 47 3b 23 25 3f 4d 5d 42 52 3d 60 51 26 45 7d
0000020 50 2e 3e 51 5c 2c 2d 20 52 55 47 7d 22 58 47 46
0000040 45 0a 4d 36 5a 54 53 41 48 27 4f 49 5d 4c 22 3a
0000060 4e 57 5e 4f 5c 4b 39 7e 42 55 49 35 38 5f 4a 30
0000100 3b 2c 53 40 0a 48 45 45 7d 7b 21 4a 36 26 5a 56
0000120 27 59 45 53 55 5a 5a 44 22 5e 27 28 58 54 55 3c
0000140 4e 7d 53 44 4c 2d 4d 4f 43 52 7b 59 43 59 4f 41
0000160 37 26 2d 32 4e 4c 54 57 24 35 51 59 2a 0a 4a 23
0000200 4b 48 4c 55 4c 5d 54 3e 4d 2f 32 4b 44 57 52 2c
...
0003021

The output I want is like:

0000000 f3 0f f4 7f f3 bf f2 3f f2 5f f3 ff f4 df f5 df f4 2f f5 2f f3 df f6 0f f5 1f f2 6f f4 5f f7 df
0000020 f5 0f f2 ef f3 ef f5 1f f5 cf f2 cf f2 df f2 0f f5 2f f5 5f f4 7f f7 df f2 2f f5 8f f4 7f f4 6f

This is my last attempt, but I get 31 31 31 31 00 instead of 1111:

    FILE *in, *f4;
    in = fopen("input.bin", "rb");
    char ch;
    char ao[] = "1111";
    f4 = fopen("output.bin", "wb+");
    while (ch != EOF) {
        if ((ch = fgetc(in)) != EOF) {
            printf("%c ", ch);
            fwrite(ao, 1, sizeof(ao), f4);
            fprintf(f4, "%c", ch);
            fwrite(ao, 1, sizeof(ao), f4);

        }
    }
    fclose(in);
    fclose(f4);

Can you help me?

[ad_2]

  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 4994 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 1084 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 1028 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

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.