Solved

Convert 10bit to 16bit int

Posted on 2006-06-10
2
616 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
ID: 16881438
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
ID: 16884251
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

828 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