Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
please send me the coding with out using bitset and bitget function please send me the coding

eg:
29=00011101
apply complement to 1st,3rd,5th,7th position from right to left
i got 72=01001000

please send me the coding
Posted
Updated 13-Feb-15 18:47pm
v2

1 solution

Well it really odd why you want to do this without bitset or bitget function. But anway here is the algorithm to do the same

0. Convert the number to bit array
1. Iterate with the array
1.1. newbit= 1- oldbit for each odd elements
2. Convert the bit array to number.


or
use this in step 1 array(0:1:end) = 1 - array(0:1:end);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900