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 8535823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:31:26+00:00 2026-06-11T10:31:26+00:00

Yes, I have read solutions for about 5 hours, none of them work. BitConverter

  • 0

Yes, I have read solutions for about 5 hours, none of them work.
BitConverter just creates a blank string.

Basically what I’m doing is trying to create a level reader, which will read a levels contents via hex and eventually display it in a treeview. So the first thing I have to do is make a byte array in which I can edit the data, I’ve done that.
However, now I want to display the data on the screen. To my knowledge you can’t display a byte array on screen, you must first convert it to a string.

So that’s what I’m trying to do:

        using (OpenFileDialog fileDialog = new OpenFileDialog())
        {
            if (fileDialog.ShowDialog() != DialogResult.Cancel)
            {
                textBox1.Text = fileDialog.FileName;
                using (BinaryReader fileBytes = new BinaryReader(new MemoryStream(File.ReadAllBytes(textBox1.Text))))
                {
                    string s = null;
                    int length = (int)fileBytes.BaseStream.Length;
                    byte[] hex = fileBytes.ReadBytes(length);
                    File.WriteAllBytes(@"c:\temp_file.txt", hex);
                }
            }
        }
    }

Note: i have removed my conversion attempts as nothing I have tried worked.
Does anyone know how I could use this data and convert it to a string, and add it to a textbox? (I know how to do the latter, of course. It’s the former that I’m having difficulties with.)
If so, please provide examples.

I probably should have made myself more clear; I don’t want to convert the byte to the corresponding character (i.e. if It is 0x43, I DON’T want to print ‘C’. I want to print ’43’.

  • 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-06-11T10:31:27+00:00Added an answer on June 11, 2026 at 10:31 am

    Do you know in which encoding your byte array is stored?

    You need Encoding.GetString method

    Here is MSDN example

    using System;
    using System.IO;
    using System.Text;
    
    public class Example
    {
       const int MAX_BUFFER_SIZE = 2048;
       static Encoding enc8 = Encoding.UTF8;
    
       public static void Main()
       {
          FileStream fStream = new FileStream(@".\Utf8Example.txt", FileMode.Open);
          string contents = null;
    
          // If file size is small, read in a single operation. 
          if (fStream.Length <= MAX_BUFFER_SIZE) {
             Byte[] bytes = new Byte[fStream.Length];
             fStream.Read(bytes, 0, bytes.Length);
             contents = enc8.GetString(bytes);
          }
          // If file size exceeds buffer size, perform multiple reads. 
          else {
             contents = ReadFromBuffer(fStream);
          }
          fStream.Close();
          Console.WriteLine(contents);
       }
    
       private static string ReadFromBuffer(FileStream fStream)
       {
            Byte[] bytes = new Byte[MAX_BUFFER_SIZE];
            string output = String.Empty;
            Decoder decoder8 = enc8.GetDecoder();
    
            while (fStream.Position < fStream.Length) {
               int nBytes = fStream.Read(bytes, 0, bytes.Length);
               int nChars = decoder8.GetCharCount(bytes, 0, nBytes);
               char[] chars = new char[nChars];
               nChars = decoder8.GetChars(bytes, 0, nBytes, chars, 0);
               output += new String(chars, 0, nChars);                                                     
            }
            return output;
        }
    }
    // The example displays the following output: 
    //     This is a UTF-8-encoded file that contains primarily Latin text, although it 
    //     does list the first twelve letters of the Russian (Cyrillic) alphabet: 
    //      
    //     А б в г д е ё ж з и й к 
    //      
    //     The goal is to save this file, then open and decode it as a binary stream.
    

    EDIT

    If you want to print out byte array in hex format, BitConverter is what you are looking form, here is MSDN example

    // Example of the BitConverter.ToString( byte[ ] ) method. 
    using System;
    
    class BytesToStringDemo
    {
        // Display a byte array with a name. 
        public static void WriteByteArray( byte[ ] bytes, string name )
        {
            const string underLine = "--------------------------------";
    
            Console.WriteLine( name );
            Console.WriteLine( underLine.Substring( 0, 
                Math.Min( name.Length, underLine.Length ) ) );
            Console.WriteLine( BitConverter.ToString( bytes ) );
            Console.WriteLine( );
        }
    
        public static void Main( )
        {
            byte[ ] arrayOne = {
                 0,   1,   2,   4,   8,  16,  32,  64, 128, 255 };
    
            byte[ ] arrayTwo = {
                32,   0,   0,  42,   0,  65,   0, 125,   0, 197,
                 0, 168,   3,  41,   4, 172,  32 };
    
            byte[ ] arrayThree = {
                15,   0,   0, 128,  16,  39, 240, 216, 241, 255, 
               127 };
    
            byte[ ] arrayFour = {
                15,   0,   0,   0,   0,  16,   0, 255,   3,   0, 
                 0, 202, 154,  59, 255, 255, 255, 255, 127 };
    
            Console.WriteLine( "This example of the " +
                "BitConverter.ToString( byte[ ] ) \n" +
                "method generates the following output.\n" );
    
            WriteByteArray( arrayOne, "arrayOne" );
            WriteByteArray( arrayTwo, "arrayTwo" );
            WriteByteArray( arrayThree, "arrayThree" );
            WriteByteArray( arrayFour, "arrayFour" );
        }
    }
    
    /*
    This example of the BitConverter.ToString( byte[ ] )
    method generates the following output.
    
    arrayOne
    --------
    00-01-02-04-08-10-20-40-80-FF
    
    arrayTwo
    --------
    20-00-00-2A-00-41-00-7D-00-C5-00-A8-03-29-04-AC-20
    
    arrayThree
    ----------
    0F-00-00-80-10-27-F0-D8-F1-FF-7F
    
    arrayFour
    ---------
    0F-00-00-00-00-10-00-FF-03-00-00-CA-9A-3B-FF-FF-FF-FF-7F
    */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have you worked in WPF? If yes you might have kown about the templates
Yes, I have searched and tried many techniques, but nothing seems to work. Here
So yes, I read about how edit distance can be used between strings to
I have read through about every possible solution online, and I get a different
First up - yes, I have read the multiple questions & answers on this
Yes I have a project that I'm working on in NetBeans 7.1 and I
I am writing a menu driven shell script and I have yes / no
(Before I start, yes I have asked a similar question before; unfortunately due to
I have seen config files(yes, text files) for various console applications that look like
I have a very simple yes no question: should static methods have same result

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.