| | |
String -> Binary -> TextBox -> AARGH!
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2006
Posts: 21
Reputation:
Solved Threads: 0
Hey all, I'm trying what must be the very simplest of tasks but I can't work out how to get my binary string to a textbox! Any suggestions?
Thanks for reading!
C# Syntax (Toggle Plain Text)
//Existing string from another text box "rev" MemoryStream ms_memStream = new MemoryStream(); BinaryWriter br_binaryWriter = new BinaryWriter(ms_memStream); try { br_binaryWriter.Write(rev); } catch (Exception ex) { MessageBox.Show(ex.Message); }
+[->,----------]<[+++++++++++.<]
Never really worked with a binary writer, but where exactly are you trying to put it into the textbox? Are you getting any errors or just not getting the right output?
From the looks of it you actually need to just tell your code to put it into the correct area. Try this:
br_binaryWriter.Write(textBox1.Text);
From the looks of it you actually need to just tell your code to put it into the correct area. Try this:
br_binaryWriter.Write(textBox1.Text);
Sir David Healy - Northern Ireland Goal King
wont let me edit so here is a double post. sorry about that:
this will convert any string to its binary compliment
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace stringToBinary { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void m_ConvertToBin_Click(object sender , EventArgs e) { m_Converted.Text = ""; string _someString = m_String.Text; if (_someString == string.Empty || _someString == null) { _someString = " "; } ASCIIEncoding _toBinary = new ASCIIEncoding(); byte[] _stringRepresentation = _toBinary.GetBytes(_someString); foreach (byte _byte in _stringRepresentation) { double _preDecimal = 0 , _aftDecimal = 0 , _num = (double)_byte , _binConst = 2; int _Binary = 0; /* * predecimal is the numbers before the decimal place so in 4.9 it would be the 4 * aftDecimal is the numbers after the decimal place; so in 4.9 it would be the 9 */ //since we are working with a byte of data we have 8 binary digits for (int i = 0 ; i < 8 ; ++i) { if (_num != 0) { if (i == 0) { //get the before and after decimal places _preDecimal = (double)System.Math.Floor((decimal)(_num / _binConst)); _aftDecimal = (_num / _binConst) % 1; //add them to the binary number _Binary = (int)_aftDecimal * (int)_binConst; //update the number we are working with _num = (int)_preDecimal; } if (i == 1) { //get the before and after decimal places _preDecimal = (double)System.Math.Floor((decimal)(_num / _binConst)); _aftDecimal = (_num / _binConst) % 1; //add them to the binary number _Binary += (int)(_aftDecimal * _binConst) * 10; //update the number we are working with _num = (int)_preDecimal; } if (i == 2) { //get the before and after decimal places _preDecimal = (double)System.Math.Floor((decimal)(_num / _binConst)); _aftDecimal = (_num / _binConst) % 1; //add them to the binary number _Binary += (int)(_aftDecimal * _binConst) * 100; //update the number we are working with _num = (int)_preDecimal; } if (i == 3) { //get the before and after decimal places _preDecimal = (double)System.Math.Floor((decimal)(_num / _binConst)); _aftDecimal = (_num / _binConst) % 1; //add them to the binary number _Binary += (int)(_aftDecimal * _binConst) * 1000; //update the number we are working with _num = (int)_preDecimal; } if (i == 4) { //get the before and after decimal places _preDecimal = (double)System.Math.Floor((decimal)(_num / _binConst)); _aftDecimal = (_num / _binConst) % 1; //add them to the binary number _Binary += (int)(_aftDecimal * _binConst) * 10000; //update the number we are working with _num = (int)_preDecimal; } if (i == 5) { //get the before and after decimal places _preDecimal = (double)System.Math.Floor((decimal)(_num / _binConst)); _aftDecimal = (_num / _binConst) % 1; //add them to the binary number _Binary += (int)(_aftDecimal * _binConst) * 100000; //update the number we are working with _num = (int)_preDecimal; } if (i == 6) { //get the before and after decimal places _preDecimal = (double)System.Math.Floor((decimal)(_num / _binConst)); _aftDecimal = (_num / _binConst) % 1; //add them to the binary number _Binary += (int)(_aftDecimal * _binConst) * 1000000; //update the number we are working with _num = (int)_preDecimal; } if (i == 7) { //get the before and after decimal places _preDecimal = (double)System.Math.Floor((decimal)(_num / _binConst)); _aftDecimal = (_num / _binConst) % 1; //add them to the binary number _Binary += (int)(_aftDecimal * _binConst) * 10000000; //update the number we are working with _num = (int)_preDecimal; } } } m_Converted.Text += _Binary.ToString() + "--"; } } } }
this will convert any string to its binary compliment
Dont forget to spread the reputation to those that deserve!
![]() |
Similar Threads
- string binary output (C++)
- conversion of string into binary (C#)
- Read a string from a binary file into a C or C++ string (C++)
Other Threads in the C# Forum
- Previous Thread: Decimal Number to Binary String
- Next Thread: Exprot to Excel in ASP.NET using C#
| Thread Tools | Search this Thread |
.net access algorithm array barchart bitmap box broadcast c# check checkbox client combobox control conversion csharp custom cyclethruopenforms data database datagrid datagridview dataset date/time datetime degrees development draganddrop drawing encryption enum event excel file filename finalyearproject form format forms function gdi+ getoutlookcontactusinfcsvfile globalization gtk httpwebrequest image index input install installer java label list listbox mandelbrot math mono mouseclick mysql operator panel path photoshop picturebox pixelinversion post programming radians regex remote remoting richtextbox save server silverlight sleep socket sql sql-server statistics stream string table text textbox thread time timer timespan update usercontrol users validate validation visualstudio webbrowser windows winforms wpf xml






