Solved

# Convert 10bit to 16bit int

Posted on 2006-06-10
505 Views
How can i convert 10bit value to 16 bit int in c#
0
Question by:obeser

LVL 10

Accepted Solution

_Katka_ earned 250 total points
Hi again, I have answered the question under your previous question.. but to be exact:

1) Endianess is not applied to this example because it's 10-bit number (thus b10...b1 in any case)
2) try to read all the data in buffer (or alternatively the LCM of 10 and 16 bits = 80 bits = 8 bytes per buffer)
3) make a function:

public Boolean GetBit(int bitIndex, List<Byte> bitField)
{
return (bitField[bitIndex / 8] & (1 << (bitIndex % 8))) > 0;
}

4) go thru the buffer bits step by step:

public List<Int32> Convert10BitTo16Bit(List<Byte> inputBuffer)
{
Int32 actualValue = 0;
List<Int32> outputBuffer = new List<Int32>();

for (int a = 0; a < yourBuffer.Length * 8; a++)
{
// every ten bits store the actual 16-bit value
if (a != 0 && a % 10 == 0)
{
actualValue = 0;
}

// sum the current bit to our actual value
if (GetBit(a, inputBuffer))
{
actualValue += 1 << (9 - (a % 10));
}
}

return outputBuffer;
}

regards,
Kate
0

Author Comment

Hi Kate I have graded your solution AA at first look. Because it seems to work. But when i tried to run it
i noticed that it does not work correctly.

1- it does not handle all the buffer you always got 1 member missing. that is
(int a = 0; a < yourBuffer.Length * 8) syntax it does not deal with last 10 bit
2-In conversion i think there is a problem.

Ozgur

0

## Featured Post

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…