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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:32:24+00:00 2026-06-06T01:32:24+00:00

Briefly: Question is related to bitwise operations on hex – language C ; O.S:

  • 0

Briefly: Question is related to bitwise operations on hex – language C ; O.S: linux

I would simply like to do some bitwise operations on a “long” hex string.
I tried the following:

First try:

I cannot use the following because of overflow:

long  t1 = 0xabefffcccaadddddffff;
and t2 = 0xdeeefffffccccaaadacd;

Second try: Does not work because abcdef are interpreted as string instead of hex

char* t1 = "abefffcccaadddddffff";
char* t2 = "deeefffffccccaaadacd";

int len = strlen(t1);

for (int i = 0; i < len; i++ )
    {
        char exor = *(t1 + i) ^ *(t2 + i);
    printf("%x", exor);
}

Could someone please let me know how to do this? thx

  • 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-06-06T01:32:26+00:00Added an answer on June 6, 2026 at 1:32 am

    Bitwise operations are usually very easily extended to larger numbers.

    The best way to do this is to split them up into 4 or 8 byte sequences, and store them as an array of uints. In this case you need at least 80 bits for those particular strings.

    For AND it is pretty simple, something like:

    unsigned int A[3] = { 0xabef, 0xffcccaad, 0xddddffff };
    unsigned int B[3] = { 0xdeee, 0xfffffccc, 0xcaaadacd };
    unsigned int R[3] = { 0 };
    
    for (int b = 0; b < 3; b++) {
        R[b] = A[b] & B[b];
    }
    

    A more full example including scanning hex strings and printing them:

    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    
    typedef unsigned int uint;
    
    void long_Print(int size, const uint a[]) {
        printf("0x");
        for (int i = 0; i < size; i++) {
            printf("%x", a[i]);
        }
    }
    
    void long_AND(int size, const uint a[], const uint b[], uint r[]) {
        for (int i = 0; i < size; i++) {
            r[i] = a[i] & b[i];
        }
    }
    
    // Reads a long hex string and fills an array. Returns the number of elements filled.
    int long_Scan(int size, const char* str, uint r[]) {
        int len = strlen(str);
        int ri = size;
    
        for (const char* here = &str[len]; here != str; here -= 8) {
            if (here < str) {
                char* tmp = (char*)malloc(4);
    
                tmp[0] = '%';
                tmp[1] = (char)(str - here + '0');
                tmp[2] = 'x';
                tmp[3] = '\0';
    
                sscanf(str, tmp, &r[ri--]);
    
                free(tmp);
    
                break;
            }
            else {
                sscanf(here, "%8x", &r[ri--]);
            }
        }
    
        for (; ri >= 0; ri--) {
            r[ri] == 0;
        }
    
        return size - ri;
    }
    
    int main(int argc, char* argv[])
    {
        uint A[3] = { 0 };
        uint B[3] = { 0 };
        uint R[3] = { 0 };
    
        long_Scan(3, "abefffcccaadddddffff", A);
        long_Scan(3, "deeefffffccccaaadacd", B);
    
        long_Print(3, A);
        puts("\nAND");
        long_Print(3, B);
        puts("\n=");
    
        long_AND(3, A, B, R);
        long_Print(3, R);
    
        getchar();
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(Briefly, like this question but for Windows servers.) I have several Win2003 servers running
I have more of a 'problem solving' question than a syntax related problem. Briefly,
This is linked to a question I asked yesterday. Briefly, the problem I'm having
Please can some one briefly tell me with example what does the means of
I read an article the other day that briefly touched base on some common
I would really appreciate it anybody could briefly explain me, what's the general approach
I have overlay View managed by WindowManager , just like in this question .
This question is related to SQL server migration. I know BCP is used for
Related to this question here , but I decided to ask another question for
My ASP.NET MVC project has some chapter class and related tag class They have

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.