Created
April 12, 2015 03:17
-
-
Save petiahr/a12e77d46ce3488832ab to your computer and use it in GitHub Desktop.
BitSequenceExchange
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
class BitSequenceExchange | |
{ | |
static void Main(string[] args) | |
{ | |
uint number = uint.Parse(Console.ReadLine()); | |
uint bits_3_4_5 = (number >> 3) & 7; | |
uint bits_24_25_26 = (number >> 24) & 7; | |
// Create new number, where the bits 3,4,5 move to position 24,25,26 and the bits 24,25,26 move to position 3,4,5: | |
uint newByteNumber = (bits_3_4_5 << 24) | (bits_24_25_26 << 3); | |
uint mask = (7 << 3) | (7 << 24); | |
//Create new number from the given number, where the bits at position 3,4,5,24,25,26 change to 0 via (number & ~mask) | |
number = (number & ~mask)|newByteNumber; | |
Console.WriteLine(number); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment