Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6021793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:45:54+00:00 2026-05-23T03:45:54+00:00

I am reading from serial port using string messaga = _serialPort.ReadLine(); When i Console.WriteLine(messaga);

  • 0

I am reading from serial port using string messaga = _serialPort.ReadLine();
When i Console.WriteLine(messaga); random characters appear on the screen which is logical because the binary data is non ASCII.
I suppose the method I am using handles data as ascii.
What i would like to do is create a string var and asign to it the binary raw data coming from the port so when I console.write this var I want to see a string with binary data like 1101101110001011010 and NOT characters. How can i manage that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:45:54+00:00Added an answer on May 23, 2026 at 3:45 am

    You mean like this?

    class Utility
    {
      static readonly string[] BitPatterns ;
      static Utility()
      {
        BitPatterns = new string[256] ;
        for ( int i = 0 ; i < 256 ; ++i )
        {
          char[] chars = new char[8] ;
          for ( byte j = 0 , mask = 0x80 ; mask != 0x00 ; ++j , mask >>= 1 )
          {
            chars[j] = ( 0 == (i&mask) ? '0' : '1' ) ;
          }
          BitPatterns[i] = new string( chars ) ;
        }
        return ;
      }
    
      const int BITS_PER_BYTE = 8 ;
      public static string ToBinaryRepresentation( byte[] bytes )
      {
        StringBuilder sb = new StringBuilder( bytes.Length * BITS_PER_BYTE ) ;
    
        foreach ( byte b in bytes )
        {
          sb.Append( BitPatterns[b] ) ;
        }
    
        string instance = sb.ToString() ;
        return instance ;
      }
    
    }
    class Program
    {
      static void Main()
      {
        byte[] foo = { 0x00 , 0x01 , 0x02 , 0x03 , } ;
        string s   = Utility.ToBinaryRepresentation( foo ) ;
        return ;
      }
    }
    

    Benchmarked this just now. The above code is approximately 12x faster than using Convert.ToString() and approximately 17x faster if the correction is added to pad with leading ‘0’s.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm reading data from a serial port using an event listener from the SerialPort
I'm using RXTX to read data from a serial port. The reading is done
I previously have been reading NMEA data from a GPS via a serial port
I'm reading data from a serial port. I read this posting: http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/a709d698-5099-4e37-9e10-f66ff22cdd1e He is
I am reading data from multiple serial ports. At present I am using a
I'm reading data from a serial port, but the DataReceived event of SerialPort is
So, I am reading from ModBos over serial port and get readings something like
I got the code below from a website,and this way of serial port reading
Is there a way to generate random number on Windows by reading from a
I'm having problems redirecting stdio of another program using subprocess module. Just reading from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.