R
Russell Mangel
Guest
/*
* Environment: Visual Studio 2010 (Dotnet 4.0) (Legacy Project)
This code works. Is there a better way to extract the two middle bits?
Here are the four possible values for the two middle bits. */
Byte b00 = Convert.ToByte("11100111", 2);
Byte b01 = Convert.ToByte("11101111", 2);
Byte b10 = Convert.ToByte("11110111", 2);
Byte b11 = Convert.ToByte("11111111", 2);
/*
Shift first three bits off to the left.
Then shift everything back 6 bits.
There must be a cleaner better way?*/
Byte zero = (Byte)((Byte)(b00 << 3) >> 6);
Byte one = (Byte)((Byte)(b01 << 3) >> 6);
Byte two = (Byte)((Byte)(b10 << 3) >> 6);
Byte three = (Byte)((Byte)(b11 << 3) >> 6);
Console.WriteLine(zero); // Prints 0
Console.WriteLine(one); // Prints 1
Console.WriteLine(two); // Prints 2
Console.WriteLine(three);// Prints 3
/*
* Thanks for your time.
* *
Continue reading...
* Environment: Visual Studio 2010 (Dotnet 4.0) (Legacy Project)
This code works. Is there a better way to extract the two middle bits?
Here are the four possible values for the two middle bits. */
Byte b00 = Convert.ToByte("11100111", 2);
Byte b01 = Convert.ToByte("11101111", 2);
Byte b10 = Convert.ToByte("11110111", 2);
Byte b11 = Convert.ToByte("11111111", 2);
/*
Shift first three bits off to the left.
Then shift everything back 6 bits.
There must be a cleaner better way?*/
Byte zero = (Byte)((Byte)(b00 << 3) >> 6);
Byte one = (Byte)((Byte)(b01 << 3) >> 6);
Byte two = (Byte)((Byte)(b10 << 3) >> 6);
Byte three = (Byte)((Byte)(b11 << 3) >> 6);
Console.WriteLine(zero); // Prints 0
Console.WriteLine(one); // Prints 1
Console.WriteLine(two); // Prints 2
Console.WriteLine(three);// Prints 3
/*
* Thanks for your time.
* *
Continue reading...