Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 14-08-2009
Member
 
Join Date: Nov 2008
Posts: 1,022
How to convert bytes to bits

I am creating a small program in C# to convert bytes to bits. This program then will be used in some other program. But the problem is that I am unable to generate the logic that can be used. I mean what should be the logic for the program. Any ideas how to convert bytes to bits?
Reply With Quote
  #2  
Old 14-08-2009
Member
 
Join Date: May 2008
Posts: 685
Re: How to convert bytes to bits

Why don't you use some online tools such as Byte Converter? This tool will convert file storage size from one unit of measurement to another. The results will return all possible conversion options (bits, bytes, kilobytes, megabytes, gigabytes, terabytes, petabytes, and exabytes). For more information, visit this.
Reply With Quote
  #3  
Old 14-08-2009
Member
 
Join Date: Nov 2008
Posts: 1,221
Re: How to convert bytes to bits

Here is the basic code:

Code:
for (int i = 0; i < fReal.Length; i++)
{
Int16 temp = (Int16)data[i];
byte high = Convert.ToByte((temp >> 8) & 0xff);
byte low = Convert.ToByte(temp & 0xff);
sw.Write(high);
sw.Write(low);
}
Reply With Quote
  #4  
Old 14-08-2009
Member
 
Join Date: Nov 2008
Posts: 996
Re: How to convert bytes to bits

My piece of code would be:

Code:
public byte[] ToByteArray(this bool[] myNumber)
{
    var bytes = new byte[myNumber.Length / 8];
    for (int i = 0, j = 0; j < myNumber.Length; i++, j += 8)
    {
        for (int offset = 0; offset < 8; offset++)
            bytes[i] |= (myNumber[j + offset] << offset);
    }
    return bytes;
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to convert bytes to bits"
Thread Thread Starter Forum Replies Last Post
SanDisk flash drive ?0 bytes used and 0 bytes free? Coloma Hardware Peripherals 5 03-12-2012 10:56 AM
Local Disk Q: shows Free Space- 0 bytes, Total Space- 0 bytes and Access Denied message mADiRAkSHii Hardware Peripherals 5 30-01-2012 05:42 PM
Convert IP address to array of bytes Gunner 1 Software Development 5 03-03-2010 11:54 AM
How to convert Bytes to Megabytes Girish-S India BroadBand 2 15-06-2009 02:47 PM
Convert a string to bytes $tatic Software Development 4 18-02-2009 02:29 PM


All times are GMT +5.5. The time now is 06:19 AM.