Solved

Convert 10bit to 16bit int

Posted on 2006-06-10
2
505 Views
Last Modified: 2010-04-16
How can i convert 10bit value to 16 bit int in c#
0
Comment
Question by:obeser
2 Comments
 
LVL 10

Accepted Solution

by:
_Katka_ earned 250 total points
Comment Utility
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)
            {
                  outputBuffer.Add(actualValue);
                  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

by:obeser
Comment Utility
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.

if you revise please revise your solution i would be happy.
Ozgur

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now