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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:03:11+00:00 2026-06-11T17:03:11+00:00

Simple question here. Having a problem with the XOR operator (^). I can XOR

  • 0

Simple question here. Having a problem with the XOR operator (^). I can XOR integers fine and get the correct results; however, when XORing two chars, nothing is returned:

int main() {
    char a = 'a';
    char b = 'b';
    char c;

    c = a^b;
    cout << c << endl;
}

Nothing happens. No output. What am I doing wrong here. I’m trying to use this to XOR encrypt a string with a given key, but am having issues with this operation. I guess I could get the ASCII value and convert it to its corresponding char, but this tool will be used to encrypt files as well as plain text so I would like to avoid that at all costs.

  • 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-11T17:03:12+00:00Added an answer on June 11, 2026 at 5:03 pm

    std::ostream::operator<< (and std::cout is an std::ostream) outputs formatted text. When you pass it a char, it’s trying to format and output a character (think ASCII). If the char isn’t a printable character, it doesn’t print it out (for obvious reasons). If you want it to output a formated integer, you need to cast it:

    char a = 'a'; // 'a' == 0x61
    char b = 'b'; // 'b' == 0x62
    char c = a ^ b; // 0x61 ^ 0x62 == 0x03
    std::cout << static_cast<int>(c) << std::endl;
    

    For what it’s worth, if you use the unformatted output function std::ostream::write, it will output unformatted characters. Beware, however, because if you try to write out an unprintable character, it will “work,” but your console will not show it (because again, it’s an unprintable character).

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

Sidebar

Related Questions

I'm having a problem with parsing XML in Android app, a question here implies
I asked this question before, Here however I think I presented the problem poorly,
Simple question here: I like to know if a constraint in a oracle database
Simple question here: is there any way to convert from a jagged array to
Simple question here for Excel addict: =0.23-0.0373*SIN(B2-PI) X Y 0 0.24 #NAME? 0.1 -0.758334166
a simple question here Is there a way to change the text click here
Really simple question here but bugging me for long enough to ask. Code looks
Right, simple question here. I couldn't find an answer using google and looking here.
I am very new to Perl, so please bear with my simple question: Here
Here comes a simple question, for all those who know javascript. I made an

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.