Byte 01011
22-04-2011 22:02
к комментариям - к полной версии
- понравилось!
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
byte[] byteArray = new byte[] { 0xAA, 0X55 };
byte[] b = GetSelectiveBits(byteArray);
Console.Write("{0:X}", b[0]);
Console.ReadKey();
}
static byte[] GetSelectiveBits(byte[] byteArray)
{
byte[] ret = new byte[byteArray.Length / 2];
for (int i = 0; i < byteArray.Length; )
{
byte b1 = byteArray[i];
byte b2 = (i + 1 < byteArray.Length ? byteArray[i + 1] : (byte)0);
byte b = 0;
for (int j = 7; j >= 0; j -= 2)
{
byte mask = 1;
mask <<= j;
b <<= 1;
if ((mask & b1) != 0)
b += 1;
}
for (int j = 7; j >= 0; j -= 2)
{
byte mask = 1;
mask <<= j;
b <<= 1;
if ((mask & b2) != 0)
b += 1;
}
ret[i / 2] = b;
i += 2;
}
return ret;
}
}
}
вверх^
к полной версии
понравилось!
в evernote