0xDEAD10CC Programming Challenge #2 03-05-2014, 03:39 AM
#1
Objective: Use only bitwise operations to swap the bits of an integer so that the following digit POSITIONS (marked by each unique color) within the following 32 bit int (in hex format below) are swapped, and assigned back to the original int:
0x123456
1 < - > 5
2 < - > 3
4 < - > 6
Correct Result: 0x532614
Challenge/Bonus: Start off with an integer in hex format with digits 1-6 randomized in terms of position, and swap based on the digit itself, where the position might not always be the same, according to the following map:
Examples:
1. 0x123456 = 0x465132
2. 0x246135 = 0x612453
In layman's terms, where ever 1 is in the hex format, swap it with 4, swap 2 with where ever 6 is, and 3 with 5.
*Optional: Use all values from 0-F instead of just numeric digits for hex format.
You MUST ONLY use math and bitwise operations to move the digits around. No casting to a string and re-interpreting it after string manipulation or any other cheap tricks...
0x123456
1 < - > 5
2 < - > 3
4 < - > 6
Correct Result: 0x532614
Challenge/Bonus: Start off with an integer in hex format with digits 1-6 randomized in terms of position, and swap based on the digit itself, where the position might not always be the same, according to the following map:
Code:
1 < - > 4
2 < - > 6
3 < - > 5Examples:
1. 0x123456 = 0x465132
2. 0x246135 = 0x612453
In layman's terms, where ever 1 is in the hex format, swap it with 4, swap 2 with where ever 6 is, and 3 with 5.
*Optional: Use all values from 0-F instead of just numeric digits for hex format.
You MUST ONLY use math and bitwise operations to move the digits around. No casting to a string and re-interpreting it after string manipulation or any other cheap tricks...




![[+]](https://sinister.li/images/modern/collapse_collapsed.png)





![[Image: CDUAq9d.png]](http://i.imgur.com/CDUAq9d.png)