CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2014

    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.

  2. #2
    Join Date
    Oct 2004
    Rocket City

    Re: converting bits sequence into binary or string

    You could try the System.Collections.BitArray class and its Cast<> method.

  3. #3
    Join Date
    Apr 2014
    in northeast ohio

    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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.