Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- namespace TextToBin
- {
- class Program
- {
- static void Main()
- {
- Console.Title = "Nico aka f0rkB0mb's Text2Bin-Converter";
- /** if you wanna check the indexes of the ASCII-Code **/
- /**
- Console.WriteLine("ASCII:");
- for (int ascii = 33; ascii < 256; ascii++)
- {
- Console.Write(ascii.ToString() + ") " + Convert.ToChar(ascii) + ", ");
- if (ascii % 10 == 0)
- Console.WriteLine();
- }
- **/
- Console.WriteLine("Please insert Textphrase: ");
- string str = Console.ReadLine();
- char[] work = str.ToCharArray(); //push the entered string in a char-array (could also be done within a for-loop)
- /** if you wanna check the single chars that was entered **/
- /**
- Console.WriteLine("Your Text as single Chars: ");
- for (int i = 0; i < work.Length; i++)
- Console.Write("'" + work[i] + "'");
- Console.WriteLine();
- **/
- int[] convert = new int[work.Length];
- for (int i = 0; i < work.Length; i++)
- {
- convert[i] = (int)work[i]; //int.Parse(work[i]) does the same
- Console.WriteLine("{0}={1}", work[i], decimal2dual(convert[i], 8));
- }
- Console.ReadLine();
- }
- private static string decimal2dual(int decNbr, int bitWidth)
- {
- StringBuilder strBuildr = new StringBuilder();
- //we convert it via bitshifting!
- for (int i = 0; i < bitWidth; decNbr = decNbr >> 1, i++)
- strBuildr.Insert(0, decNbr & 1);
- return strBuildr.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement