PC Review


Reply
Thread Tools Rate Thread

Boolean values to bytes

 
 
Jay Dee
Guest
Posts: n/a
 
      4th May 2009
I would like to no how to convert an array of 16 Boolean values into
an array of 2 bytes.

I can find plenty of examples to get Booleans from bytes but can not
get my head round how to do it in reverse.

Could someone explain or point me in the right direction.

Thanks a lot

Jay Dee
 
Reply With Quote
 
 
 
 
Pavel Minaev
Guest
Posts: n/a
 
      4th May 2009
On May 3, 4:43*pm, Jay Dee <first...@gmail.com> wrote:
> I would like to no how to convert an array of 16 Boolean values into
> an array of 2 bytes.
>
> I can find plenty of examples to get Booleans from bytes but can not
> get my head round how to do it in reverse.


Do you mean that you want to pack 16 boolean values into 16 bits
(which would be 2 bytes)?

If so, then by far the easiest way to do it and avoid messing with
bitwise operators is to use BitArray:

bool[] input = new bool[16];
byte[] output = new byte[2];
....
new BitArray(input).CopyTo(output, 0);
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Evaluate boolean values as 1 or 0 hmm Microsoft Excel Worksheet Functions 3 2nd Sep 2008 01:32 PM
Using Boolean Values Paul Microsoft ASP .NET 0 20th Apr 2006 01:41 PM
Oracle Boolean Values Bob Clegg Microsoft ADO .NET 1 2nd May 2004 03:29 AM
Boolean Values TC Microsoft Access Database Table Design 4 29th Oct 2003 02:52 PM
Boolean type is 2 bytes???? Stephen Microsoft Dot NET Framework 3 1st Sep 2003 09:14 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:30 AM.