This project is read-only.

Binary Convert.NET is a free, redistributable tool for converting in between 26 different positional numeral systems (such as decimal, binary, and hexadecimal) and ASCII text.

To Install

  1. Download the .ZIP folder from the downloads page.
  2. Extract it into any directory.
  3. Open the directory that you extracted the files to, and launch “Binary Convert.NET.exe”

To Use

  •  The program contains two drop-down boxes and two text boxes.
  • When you type into one box, it will convert from that box’s drop-down selection into the other box’s selection, putting the converted text in the other box.
  • Two-way conversion is supported: type in either box to convert.
  • Only characters supported by your selected numeral system are supported; un-supported characters will be filtered out. For example, if you have selected hexadecimal, you can only type the numbers 1-9 and letters A-F. All other characters will be removed from the text box as you type them.

Binary Convert.NET can be redistrubuted and modified, as long as you attribute the original application and/or source code to Thomas Shields and share your adaptation likewise.

Also included is a VB.NET and C# class, so you can include conversions right in your VB.NET or C# applications.

To Install

  1. Download "Converter Class" from the downloads page.
  2. Add it to your project.

To Use

**NOTE** The converter class is only in VB right now. I'll add a C# class ASAP   **UPDATE**  The C# class is available for download!   

The converter class includes two simple functions: toDecimal(number, base), and fromDecimal(number, base)

toDecimal converts a number from any numeral-base system into decimal. Syntax:  toDecimal(number As String, base As Integer)

toDecimal returns the decimal number in a string, for easy parsing. It can easily be converted to an integer. To use toDecimal, declare a new instance of PNSConverter, and call PNSConverter.toDecimal(). As stated, toDecimal requires two arguments: number, and base. Number is the value to be converted, whether it be in binary, hexadecimal - you name it. Base is the number of the positional numeral system - for example, binary is 2, hexadecimal is 16, octal is 8. The following example shows the conversion of a binary number to a decimal:

VB.NET: 
Dim pns As New PNSConverter()
decimalValue = PNS.toDecimal(binaryValue, 2)
C#.NET:
PNSConverter pns = new PNSConverter();
decimalValue = pns.toDecimal(binaryValue, 2);

fromDecimal converts a number to any numeral-base system from decimal. Syntax: fromDecimal(number As String, base As Integer)

fromDecimal returns the value in a string, for easy parsing. It can easily be converted to an integer. To use fromDecimal, declare a new instance of PNSConverter, and call PNSConverter.fromDecimal(). As stated, fromDecimal requires two arguments: number, and base. Number is the value to be converted from decimal. Base is the number of the positional numeral system you are converting to- for example, binary is 2, hexadecimal is 16, octal is 8. The following example shows the conversion of a decimal number to binary:

VB.NET:
Dim pns As New PNSConverter()
binaryValue = pns.fromDecimal(decimalValue, 2)
C#:
PNSConverter pns = new PNSConverter();
binaryValue = pns.fromDecimal(decimalValue,2);

When converting from a non-decimal to another non-decimal, call fromDecimal and specify the number argument as toDecimal. This will first convert your value to a decimal, then convert the returned decimal value into the original numeral system requested:

Dim pns As New PNSConverter()
binaryValue = pns.fromDecimal(pns.toDecimal(hexadecimalValue, 16), 2)
PNSConverter pns = new PNSConverter();
binaryValue = pns.fromDecimal(pns.toDecimal(hexValue, 16), 2);

Simple error-catching is built in: if a value too large for the standard Int64 is passed to the PNSConverter class, it will return "0." Non-accepted characters are simply passed over.

A good idea is to filter out unacceptable characters before passing to PNSConverter. Since this varies based on the numeral system, try using the following code:

Dim value As String 'Value to be filtered
If base <= 10 Then
                For Each c In value
                    If IsNumeric(c) = False Then
                        value = value.Replace(c, "")
                    End If
                Next
            ElseIf base > 10 Then
                Dim decpluschars As String() = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P"}
                For Each c In value
                    If IsNumeric(c) = False Then
                        For x = 0 To base - 1
                            If c.ToString() = decpluschars(x) Then

                                GoTo skip
                            End If
                        Next
                        value = value.Replace(c, "")
skip:
                    End If
                Next
            End If

C#:

 string value = ""; // value for filtering
            int Base = 0; // base of numeral system (e.g, binary = 2, decimal = 10)

            if (Base <= 10)
            {
                foreach (char c in value)
                {
                    bool isNum;
                    double retNum;
                    isNum = Double.TryParse(Convert.ToString(digit), System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out retNum);
                    if (!isNum)
                    {
                        value = value.Replace(c.ToString(), "");
                    }

                }
            }
            else if (Base > 10)
            {
            string[] decpluschars = new string[] {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P"}
             foreach (char c in value)
             {
                 bool isNum;
                    double retNum;
                    isNum = Double.TryParse(Convert.ToString(c), System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out retNum);
                    if (!isNum)
                    {
                        for(int x=0; x <= (Base - 1); x++)
                        {
                            if(c.ToString() == decpluschars[x])
                            {
                                goto Skip;
                            }
                        }
                        value = value.Replace(c.ToString(), "");
                  Skip:
                        int dummy = 0;
                    }
             }

            }

 Thanks for using Binary Convert.NET! I'll have a C# class up ASAP. **UPDATE**  The C# class is available for download!  If you have any questions, complaints, suggestions, or found bugs, please comment in a review or discussion post.

Creative Commons License
Binary Convert.NET by Thomas Shields is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

Last edited Aug 4, 2010 at 11:51 PM by ThomasWCV, version 3

Comments

No comments yet.