answersLogoWhite

0


Best Answer

#include<stdio.h>

#include<conio.h>

void main()

{

int x,y;

clrscr();

printf("\n enter the elements\n");

scanf("%d%d",&x,&y);

printf("\n before swaping x=%d,y=%d",x,y);

x=x^y;

y=y^x;

x=x^y;

printf("\n after swaping x=%d y=%d",x,y);

getch();

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

not 100% sure if this is what you are asking for but here it goes.

you have a number 11110000 (binary) and you want 00001111 (binary)?

you want to use the xor operator ^

value = 0xf0; //11110000 binary

printf("before %d\n");

value ^= 0xff; //11111111 binary

printf("after%d\n");

output:

before 240

after 15

240 in binary is 11110000

15 in binary is 00001111

^

The example provided above gives the illusion that bit order was reversed.

Function revbyte(inbyte As Byte) As Byte

For i = 0 To 7

revbyte= revbyte Or 2 ^ (7 - i) * IIf((inbyte And 2 ^ i) > 0, 1, 0)

Next

End Function

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

If you have to bits, A and B, then their sum is {A-and-B, A-xor-B} (two bits).

Note: Sometimes you have to add three bits (A, B and C), then the sum is {(A-and-B)-or-(A-and-C)-or-(B-and-C),(A-xor-B)-xor-C} (two bits).

See the attached links for details.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

package others;

public class AddTwoNumbers {

private static int myAdd(int a, int b)

{

int carry = a & b;

int result = a ^ b;

while(carry != 0)

{

int shiftedcarry = carry << 1;

carry = result & shiftedcarry;

result ^= shiftedcarry;

}

return result;

}

public static void main(String[] args){

System.out.println(myAdd(4, 5));

System.out.println(myAdd(4, -5));

System.out.println(myAdd(-4, -5));

System.out.println(myAdd(-4, 5));

System.out.println(myAdd(0, 5));

}

}

output :

9

-1

-9

1

5

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

If you mean, in a computer program, in Python you can swap the value of two variables like this:

a, b = b, a

But in most programming languages, you need an intermediate variable:

temp = a

a = b

b = temp

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

Without temporary variable:

void swap( int& x, int&y ) { x ^= y ^= x ^= y; }

With temporary variable:

void swap( int&x, int& y ) { int t=x; x=y; y=t; }

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

a := a XOR b

b := a XOR b

a := a XOR b

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you subtraction two numbers using bitwise operator?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you find the greatest of three numbers using ternery operator?

Compare the first two numbers with the ternary operator. Store the result in a temporary variable. Compare the temporary variable with the third number, again using the ternary operator.


How do you write a javascript to swap two numbers without using third one?

By using the algorithm of bitwise EORing (Exclusive ORing) the numbers together:If the two numbers are X and Y, then to swap them:X = X EOR YY = Y EOR XX =X EOR Ywill swap them.With knowledge of that algorithm, one then uses the syntax of Javascript to implement it.


What is the use of complementry operator in c?

The bitwise complement or one's complement operator (~) is used to switch the state of all the bits in a value. Thus 1's become 0, and 0's become 1. One of its many uses is to unset individual bit(s) in a bitmap. We do this with a bitwise AND of the bitmap and the bitwise complement of the bit(s) we want to unset. Original bitmap: 01011100 Bit to unset: 00000100 (e.g., bit 2 (bits are zero based from right)) // Using one's complement and bitwise AND ~00000100 &amp; 01011100 11111011 (one's complement of bit 2) &amp; 01011100 (original bitmap) = 01011000 (original bitmap with bit 2 unset) Note that this formula works even if bit 2 were already unset: 11111011 (one's complement of bit 2) &amp; 01011000 (original bitmap, with bit 2 unset) = 01011000 (original bitmap unchanged)


How do you compare two numbers without using any operators in c?

You cannot compare 2 numbers without using relational operators. Certainly, you could subtract them, but you still need to test the result, and that is a relational operator in itself.


What is the use of Bitwise operators?

AnswerThe bitwise operators treat a number as its binary equivalent rather than as a simple boolean value.For most programming languages, a value of zero is considered FALSE and all other values are TRUEThus, 8 AND 11 returns TRUE as does 3 OR 0In bitwise analysis, each binary bit of the digit are compared. The number of bits compared will depend on the type of number.In C, a CHAR is usually 8 bits and can hold the binary numbers 0 to 255.If we compare 8 (00001000) and 19 (00010011) with bitwise operators, we get different results from Boolean operators:8 BITWISE AND 19 returns 0 (each bit in the response is set to 1 if both equivalent bits compared are 1) but 8 BITWISE OR 19 will return 27.The utility of these methods is in identifying binary data. For example, all files on a PC have the characteristics 'Hidden' 'Read Only' 'Archive' and 'System' which can be set or unset using bitwise operations on a single byte of data. In truth this is a throwback to the days of small memory capacities where saving the odd byte was essential.There are more uses of bitwise, especially in graphics, where XOR can be used to paint a sprite image to display it and then be used again to return a background to its former settings. I regret I lack the skill to explain this better.

Related questions

How do you Swap two numbers using bitwise operator C?

//lets assume a = 10; b = 20; a = a^b; b = a^b; a = a^b;


Which is the code to multiply a number num1 by 2 using bitwise operator in c?

num1 &lt;&lt;= 1; /* shift left */


What is the arithmetic operator that subtracts contents of cells?

It is Subtraction, using the minus sign. For example: =A5-C10


How do you find the difference using mixed numbers?

first add the whole numbers then do simple fraction subtraction


How do you find the greatest of three numbers using ternery operator?

Compare the first two numbers with the ternary operator. Store the result in a temporary variable. Compare the temporary variable with the third number, again using the ternary operator.


Which operations require you to align numbers using their decimal points before you begin a calculation?

Addition and subtraction.


What subtraction equals 33333 using numbers 1-9?

Professor Layton? 41268 - 7935 (or 41286 - 7153)


Does it matter when using subtraction the order in which the numbers are presented?

Yes it matters. Subtraction is not commutative. Example: 5-2 = 3 (positive three), but 2-5 = -3 (negative three)


How do you add two numbers with out using operator in c language?

Not possible. Of course you can call a function which does the addition for you, but function-calling is also an operator in C.


What is the greatest difference in a subtraction using the numbers 1 2 4 and 5 only once?

The greatest difference is 541


How many ways can you make a true subtraction problem using the numbers 1 9?

There are 175 solutions all together.


How do you make 36 using subtraction division multiplication and addition and brackets by using the numbers 2 7 4 3?

It is: 23+(4*7) = 36.