-
April 23rd, 2014, 05:03 AM
#1
converting bits sequence into binary or string
I have stored six different bits into my SQL Server database and now I want to combine that all into ASCII or otherwise in string to send on serial port. so, how could I?
my 6 different bits stored into database in six different field name as v1,...., v6. and its in format of bit.
-
April 23rd, 2014, 11:27 AM
#2
Re: converting bits sequence into binary or string
You could try the System.Collections.BitArray class and its Cast<> method.
-
April 23rd, 2014, 11:43 AM
#3
Re: converting bits sequence into binary or string
i on the sql portion no comment, as for the bits to ascii
you would could use bit math
turn the bits into a byte ...n , then
cast that byte to char c = (char)n;
though its been a minute this may not be exact
something akin to or-ing each flag to a position in a byte
byte n = 0;
n = n | bitflag05 << 5 ;
char c = (char)n;
to read it cast the char back to a byte then by and-ing &
if( n & ( (byte)1 << 5 ) > 0 ) { }
...
you would google for a tutorial on bit shifting and bit math operators for this part
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|