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 6205199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:13:46+00:00 2026-05-24T05:13:46+00:00

I wanna do some bitwise operations (for example xor two files) on files in

  • 0

I wanna do some bitwise operations (for example xor two files) on files in Linux , and I have no idea how I can do that. Is there any command for that or not?

any help will be appreciated.

  • 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-24T05:13:46+00:00Added an answer on May 24, 2026 at 5:13 am

    You can map the file with mmap, apply bitwise operations on the mapped memory, and close it.

    Alternatively, reading chunks into a buffer, applying the operation on the buffer, and writing out the buffer works too.

    Here’s an example (C, not C++; since everything but the error handlings is the same) that inverts all bits:

    #include <unistd.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <sys/mman.h>
    int main(int argc, char* argv[]) {
        if (argc != 2) {printf("Usage: %s file\n", argv[0]); exit(1);}
    
        int fd = open(argv[1], O_RDWR);
        if (fd == -1) {perror("Error opening file for writing"); exit(2);}
    
        struct stat st;
        if (fstat(fd, &st) == -1) {perror("Can't determine file size"); exit(3);}
    
        char* file = mmap(NULL, st.st_size, PROT_READ | PROT_WRITE,
                          MAP_SHARED, fd, 0);
        if (file == MAP_FAILED) {
            perror("Can't map file");
            exit(4);
        }
    
        for (ssize_t i = 0;i < st.st_size;i++) {
            /* Binary operation goes here.
            If speed is an issue, you may want to do it on a 32 or 64 bit value at
            once, and handle any remaining bytes in special code. */
            file[i] = ~file[i];
        }
    
        munmap(file, st.st_size);
        close(fd);
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i wanna write an xml schema that can accept some elements that can occur
I wanna do some local developer tests of IIS 7 but I don't have
i have this event handler Temp.MouseLeftButtonDown += new MouseButtonEventHandler(Temp_MouseLeftButtonDown); but i wanna send some
There are any control who can draw a rule regardless of the screen resolution?
I have create several canvas with transparent background and wanna make some move event
I have readed something about it i wanna to do some implementation using this.
i wanna find some text for example Joe and remove it from where it
I wanna write a program that should perform some tasks automatically if someone logs
I wanna to store some hidden data in my text box . Is there
Just wanna confirm my thoughts about CryptographicException on decryption. I have some tests, exactly

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.