#Day2 'C' Coding Challenge

#Day2 'C' Coding Challenge

 What is the output of the below code and why?

------------------------

The above code performs swap operation between variables var_1 and var_2.Let us look at the explanation below.

var_1 ^ = var_2 is expanded as var_1 = var_1^var_2
This represents XOR operation between var_1 and var_2.

For the first statement, var_1 ^ = var_2
=> var_1 = (100)^(200) = (000100000000)^(001000000000) = 001100000000 = 300

For the second statement, var_2 ^ = var_1
=> var_2 = (200)^(300) = (001000000000)^(001100000000) = 000100000000 = 100

For the third statement, var_1 ^ = var_2
=> var_1 = (300)^(100) = (001100000000)^(000100000000) = 001000000000 = 200

The final output is 200,100.

----------------------------------------

The above code snippet involved below learning:
  • Binary to Decimal/Hex conversion
  • Decimal/Hex to Binary conversion
  • XOR operation
The XOR operation truth table is as follows:


Binary to Hex/Decimal and vice versa follows below table:

Post a Comment

0 Comments