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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:10:57+00:00 2026-06-02T20:10:57+00:00

I have got an array of chars that I’m trying to bitwise shift right

  • 0

I have got an array of chars that I’m trying to bitwise shift right >>, then & with another array. I think I have got the wrong idea of how to do this.

I thought, even though it was an array of chars just stating my_array >>= 1 would shift everything but I am getting an error: "error: invalid operands to binary >> (have ‘char[8]’ and ‘int’)"

The bitwise comparision I am trying to do is with a similar size array initiated to all “0’s”…for that I’m getting: "error: invalid operands to binary & (have ‘char *’ and ‘char *’)"

Do I need to convert these array’s into something else before I can shift and compare?

Sorry, I was not super clear… All great advice up to this point and I think I am realizing more that there is no super easy way to do this. More specifically, what I am trying to do is shift the bits of the WHOLE char array right 1, adding the bit shifted off the right back to the left most side of the array, do the bitwise compare with another array of same size.

Technically the compare doesn’t have to be array with array… I just need the bits. Would it be easier to convert the array’s to something else before trying to do the shifts/comparisons?

  • 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-02T20:10:58+00:00Added an answer on June 2, 2026 at 8:10 pm

    You have to shift and compare elementwise.

    for(i = 0; i < len; ++i)
        array[i] >>= 3;
    

    for example. If you want to move the bits shifted out of one element to the next, it’s more complicated, say you’re shifting right, then

    unsigned char bits1 = 0, bits2 = 0;
    for(i = len-1; i >= 0; --i) {
        bits2 = array[i] & 0x07;
        array[i] >>= 3;
        array[i] |= bits1 << 5;
        bits1 = bits2;
    }
    

    traversing the array in the other direction because you need the bits from the next higher slot.

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

Sidebar

Related Questions

I have a 1D array that got i*50 elements..i is a random number and
i have have got an array of the complexe sort to store my navigation
I got requirements- 1. Have random values in a List/Array and I need to
I have got a Wavecom Supreme GSM modem. I wrote a simple application that
I have got a field that has been setup to allow for Null, but
I have got an ActiveX Control that gets an image from a fingerprint device
Ok, so I have a 2D Array that is initialised with values from a
I got some vectors containing unsigned chars that represent pixels from a frame. I
I have some homework that I was flying through until I got to this
I got the following problem: I have an array of char pointers char *opts[]

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.