What's happening here?

Posted on 2004-09-02
Last Modified: 2010-04-01
In the following snippet, the text is being "encrypted" or something along those lines.  I was hoping someone could tell me exactly what's being done....

char szTest[]={      
                        'T'            ^ ( char) 0x0FF,
                        'E'            ^ ( char) 0x0FF,
                        'S'            ^ ( char) 0x0FF,
                        'T'            ^ ( char) 0x0FF,

Thanks in advance,
Question by:fattumsdad
LVL 23

Assisted Solution

brettmjohnson earned 100 total points
ID: 11970214
Bit-wise Exclusive Or (XOR) (^) has the following properties:
1 ^ 1 = 0
1 ^ 0 = 1
0 ^ 1 = 1
0 ^ 0 = 0

so that a byte XOR'd with FF (all 1s), basically creates a "negative image"
of the byte - all the 0s become 1s and all all the 1s become 0s.


Accepted Solution

TrekkyLeaper earned 100 total points
ID: 11970219
That is doing a one's complement of the character value. For example:

'T' = 0101100 (in binary)

'T' ^ (char) 0x0FF => 0101100 ^ 11111111 = 1010011
LVL 11

Expert Comment

ID: 11970223
^ is the bitwise XOR operation

your T , E , S, T etc ate xor'ed against 0X0FF

LVL 11

Assisted Solution

avizit earned 100 total points
ID: 11970230
you can get the original back by XOR again with the same

the following prog will demostrate

int main(){
char szTest[]={
        'T'          ^ ( char) 0x0FF,
        'E'          ^ ( char) 0x0FF,
        'S'          ^ ( char) 0x0FF,
        'T'          ^ ( char) 0x0FF,

for(int i = 0; i < 4; i ++){
        szTest[i]^= 0x0FF;

for(int i = 0; i < 4; i ++){

  return 0;

Author Comment

ID: 11970259
I see!  Thanks to each of you for the help.  I don't like having to choose between numerous good answers, so I'm increasing to 300 pts and giving 100 to each.  Thanks again!


Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
maze travler 6 55
How do I add zip/compression functionality to a C++ (Windows and Linux) application? 3 106
How can i compile this github project?? 2 84
max float value 3 41
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question