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

  • Home
  • SEARCH
  • 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 155417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:09:08+00:00 2026-05-11T10:09:08+00:00

I have a C array like: char byte_array[10]; And another one that acts as

  • 0

I have a C array like:

char byte_array[10]; 

And another one that acts as a mask:

char byte_mask[10]; 

I would like to do get another array that is the result from the first one plus the second one using a bitwise operation, on each byte.

What’s the most efficient way to do this?

thanks for your answers.

  • 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. 2026-05-11T10:09:08+00:00Added an answer on May 11, 2026 at 10:09 am
    for ( i = 10 ; i-- > 0 ; )     result_array[i] = byte_array[i] & byte_mask[i]; 
    • Going backwards pre-loads processor cache-lines.
    • Including the decrement in the compare can save some instructions.

    This will work for all arrays and processors. However, if you know your arrays are word-aligned, a faster method is to cast to a larger type and do the same calculation.

    For example, let’s say n=16 instead of n=10. Then this would be much faster:

    uint32_t* input32 = (uint32_t*)byte_array; uint32_t* mask32 = (uint32_t*)byte_mask; uint32_t* result32 = (uint32_t*)result_array; for ( i = 4 ; i-- > 0 ; )     result32[i] = input32[i] & mask32[i]; 

    (Of course you need a proper type for uint32_t, and if n is not a power of 2 you need to clean up the beginning and/or ending so that the 32-bit stuff is aligned.)

    Variation: The question specifically calls for the results to be placed in a separate array, however it would almost certainly be faster to modify the input array in-place.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 95k
  • Answers 95k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Yes. You need to compile any C objects without /CLR,… May 11, 2026 at 7:00 pm
  • Editorial Team
    Editorial Team added an answer I always use "/OPT:REF" when creating release versions. This flag… May 11, 2026 at 7:00 pm
  • Editorial Team
    Editorial Team added an answer The minimum number of system calls any reasonable *nix style… May 11, 2026 at 7:00 pm

Related Questions

I have a very painful library which, at the moment, is accepting a C#
I have the following struct in C++: #define MAXCHARS 15 typedef struct { char
I have to read a binary file in a legacy format with Java. In
I'm trying to collect information from a textfile which contains names of organisations (without

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.