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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:27:21+00:00 2026-05-25T22:27:21+00:00

In the recent interview I got a question like this : Given a string

  • 0

In the recent interview I got a question like this :

Given a string value, find out its 127th bit and reset it, do this in C language
Reset means if that particular bit is 0 change to 1 and vice versa

I didn’t find out any algorithm for this, but I want to know about how one could solve this in C language.

Edit:

After getting the answer from few, I tried this :

#include<stdio.h>
void main()
{
    char *str="anto";
    str[15] ^= 0x80;
    printf("%s",str);
}

I get the output as : anto. Now I got strike in my head that changing a bit doesn’t change the output?

  • 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-25T22:27:22+00:00Added an answer on May 25, 2026 at 10:27 pm

    Assuming char is 8 bits and the endian is little-endian:

    char *str = ...;
    
    str[15] ^= 0x80;
    

    This will flip the 127th bit.

    EDIT:

    If the bit-endian is big-endian, then use 0x01 instead.

    The answer also depends on how the bits are numbered. If we start numbering from 0, the use 0x80. If we index from 1, then we use 0x40. (0x01 and 0x02 for big-endian)

    EDIT 2 :
    Here’s the general case: (with the same assumptions)

    char *str = ...;
    int bit = 127;
    
    int index = bit / 8;   //  Get the index
    int chbit = bit % 8;   //  Get which bit in the char
    
    int mask = 1 << chbit; //  Build the mask
    
    str[index] ^= mask;    //  XOR to flip the bit.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This recent question about sorting randomly using C# got me thinking about the way
I was faced this question while one of recent interview : class1 { virtual
Hii , I was asked this question in a recent interview for which i
I thought I had reasonable answers for this question at a recent interview, but
This was a question I was asked at my recent interview and I want
Recently, I was challenged in a recent interview with a string manipulation problem and
A recent question about string literals in .NET caught my eye. I know that
A recent question came up about using String.Format(). Part of my answer included a
In context of recent trends in interviews i have noticed that this question arises
In a recent interview one peculiar question has been asked a[]= { 1,2,3,4,5,6,7,8,9,10} When

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.