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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:43:29+00:00 2026-06-02T15:43:29+00:00

Im trying to create the following loop : int temp=0x07; if(left sensor detects){ byteTx((temp)^(1<<0));

  • 0

Im trying to create the following loop :

int temp=0x07;

if(left sensor detects){
byteTx((temp)^(1<<0)); //(toggle bit 0)
}

if(right sensor detects){
byteTx((temp)^(1<<2)); //(toggle bit 2)
}

if(front sensor left || front sensor right detects){
byteTx((temp)^(1<<1)); //(toggle bit 1)
}

However, every other if statement will toggle the correct value but reset the others (because temp is 0x07).

Question : How can I make sure that I only toggle the bit needed, and keep the others unchanged even if they were toggled by the other if statements. Basically I want to store the outputs and use that instead of temp.

Thanks for the help, if you need more info let me know.

edit

Thanks for the responses but im not asking how to toggle, I’m asking how can I make sure that the value toggled is consistent between the IF statements.

0x07 will keep resetting the other bits that are toggled in other IF statements, I want to make sure that the IF statements do not reset the other bits.

Example

0000 0111 ^(1<<0) means the output is 0000 0110

but then if for the other IF statement :

0000 0111 ^(1<<2) means the output is 0000 0011

as you see the result is 0011, which will turn the 0 bit in the first statement back to 1.

how can I prevent that ?

  • 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-02T15:43:31+00:00Added an answer on June 2, 2026 at 3:43 pm

    if you want to temp to hold the toggled bits after toggleing, you must modify it, by writing the new state back.
    soemthing like

    if(left sensor detects){
       temp=(temp)^(1<<0); //(toggle bit 0)
       byteTx(temp);
    }
    

    at the end of the loop, temp will have all the toggled bits.

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

Sidebar

Related Questions

I've been stumped trying to create an if,else loop that transposes the following: Subject:
i'm trying to create following layout: http://jsfiddle.net/BTuMH/1/ but without setting the width, like: http://jsfiddle.net/yuGyg/
I am trying to create the following table but it wont create?? use [TagHolderDB]
I'm trying the following: CREATE TABLE Table1 ( RecordNo autonumber, --error here! PersonId varchar(50),
I am trying to create a query using hibernate following the example given in
I am trying to create a mapping for the following JSON data. { Calls:
I'm trying to create my first AVD for Android 4.0.3 following the tutorials ,
I am trying to create an instance of a the following class: #ifndef Sik_GameEntity_h
I am trying to create a dangling pointer by using the following code: -(void)
when I trying to create simple DB with filestream-Enabled DB with the following Query

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.