Материал: Программная реализация механизма перевода чисел в различные системы счисления

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам

.        Официальная конференция по языку C#: news://msnews.microsoft.com/ microsoft.public.dotnet.languages.csharp.

13.    Полный справочник по С#. : Пер. с англ. - М. : Издательский дом

.        Си Шарп: Создание приложений для Windows/ В. В. Лабор.- Мн.: Харвест, 384 с.,2003.

.        Шатрова, Т. И. Языковая игра в текстах комической направленности: процессы кодирования и декодирования [Текст] : дис. … канд. филол. наук / Т. И. Шатрова ; Тульский гос. пед. ун-т им. Л. Н. Толстого. - Белгород, 2006. - 159 с.

16.    Э. Стиллмен, Дж. Грин Изучаем C#. 2-е издание <http://www.piter.com/book.phtml?978544610105> = Head First C#, 2ed. - СПб.: «Питер» <https://ru.wikipedia.org/wiki/%D0%9F%D0%B8%D1%82%D0%B5%D1%80_(%D0%B8%D0%B7%D0%B4%D0%B0%D1%82%D0%B5%D0%BB%D1%8C%D1%81%D1%82%D0%B2%D0%BE)>, 2012. - 704 с. - ISBN 978-5-4461-0105-4 <https://ru.wikipedia.org/wiki/%D0%A1%D0%BB%D1%83%D0%B6%D0%B5%D0%B1%D0%BD%D0%B0%D1%8F:%D0%98%D1%81%D1%82%D0%BE%D1%87%D0%BD%D0%B8%D0%BA%D0%B8_%D0%BA%D0%BD%D0%B8%D0%B3/9785446101054>.

.        Эндрю Троелсен Язык программирования C# 5.0 и платформа .NET 4.5, 6-е издание <http://www.williamspublishing.com/Books/978-5-8459-1814-7.html> = Pro C# 5.0 and the .NET 4.5 Framework, 6th edition. - М.: «Вильямс», 2013. - 1312 с. - ISBN 978-5-8459-1814-7 <https://ru.wikipedia.org/wiki/%D0%A1%D0%BB%D1%83%D0%B6%D0%B5%D0%B1%D0%BD%D0%B0%D1%8F:%D0%98%D1%81%D1%82%D0%BE%D1%87%D0%BD%D0%B8%D0%BA%D0%B8_%D0%BA%D0%BD%D0%B8%D0%B3/9785845918147>.

Приложение

System;System.Collections.Generic;System.ComponentModel;System.Data;System.Drawing;System.Linq;System.Text;System.Windows.Forms;перевод_в_различные_системы_счисления

{

public partial class Form1 : Form

{ public Form1()

{ InitializeComponent();

}

private void flowLayoutPanel1_Paint(object sender, PaintEventArgs e)

{ }

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)

{ comboBox1.AutoCompleteCustomSource.Add("двоичная");

comboBox1.AutoCompleteCustomSource.Add("восьмиричная");

comboBox1.AutoCompleteCustomSource.Add("десятичная");

comboBox1.AutoCompleteCustomSource.Add("шестнадцатиричная");

}

private void Form1_Load(object sender, EventArgs e)

{

}

private void button2_Click(object sender, EventArgs e)

{ {

MessageBox.Show("");

} private void (object sender, EventArgs e)

{ MessageBox.Show

private void button1_Click(object sender, EventArgs e)

{ //получает обратную запись двоичного числа из десятичного

private int perevod(int temp)

{ int temp1 = 0;

List<int> s = new List<int>();

while(temp>0)

{ temp1 = temp % 2;

temp = temp / 2;

s.Add(temp1);

}

return obrat(s);

}//переворачивает число и возвращает прямую запись двоичного числа.

private int obrat(List<int> norm)

{ int[] s= new int[norm.Count];

for (int i = norm.Count-1; i >=0 ; i--)

{ s[norm.Count-1-i] = norm[i];

} return Convert.ToInt32(string.Join<int>("",s));

}string n = textBox1.Text; .Text(radioButton2.Checked)

{int sum = 0; (int i = 0; i < n.Length; i++) {= sum * 2 + Convert.ToInt32(n.Substring(i, 1)); }.Text = sum.ToString(); // }(radioButton1.Checked)

{string sum = "";[] arr8; = new string[8] { "" };(n.Length % 3 == 0) {(int i = 0; i < n.Length; i = i + 3)

{if (n.Substring(i, 3) == arr8[j])

{sum = sum + j.ToString();

}}}.Text = sum;

}else

{MessageBox.Show("");

}}if (radioButton3.Checked)

{string sum = ""; [] arr16; = new string[16] { "" };(n.Length % 4 == 0)

{for (int i = 0; i < n.Length; i = i + 4)

{for (int j = 0; j < 16; j++)

{if (n.Substring(i, 4) == arr16[j])

{sum = sum + j.ToString();

}}}textBox2.Text = sum;

}else

{MessageBox.Show("");

}} }("");

} private void button1_Click(object sender, EventArgs e)

{ RemoveClickEvent(button2);

button2.Click += new EventHandler(v1);

}

private void button2_Click(object sender, EventArgs e)

{ RemoveClickEvent(button4);

button2.Click += new EventHandler(v2);

}

private void RemoveClickEvent(Button b)

{ FieldInfo f1 = typeof(Control).GetField("EventClick",

BindingFlags.Static | BindingFlags.NonPublic);

object obj = f1.GetValue(b);

PropertyInfo pi = b.GetType().GetProperty("Events",

BindingFlags.NonPublic | BindingFlags.Instance);

EventHandlerList list = (EventHandlerList)pi.GetValue(b, null);

list.RemoveHandler(obj, list[obj]);

}main()

{signed long int b;a[70],i,c[70],h,g;("Введите а:");("%d", &b);[1]=b/16;[2]=b%16;(h=2;h<=64;h+=2)

{a[h+1]=a[h-1]/16;[h+2]=a[h-1]%16;

}printf(for(i=64;i>=2;i-=2)

{switch(a[i])

{case 0:printf(%d;i)

}}c[0]=b/2;[1]=b%2;(g=1;g<=63;g+=2)

{c[g+1]=c[g-1]/2;[g+2]=c[g-1]%2;

}printf("for(g=63;g>=1;g-=2)

{printf("%d", c[g]);

}getch();} } }}перевод_в_различные_системы_счисления

{

partial class Form1

{

/// <summary>

/// Требуется переменная конструктора.

/// </summary>

private System.ComponentModel.IContainer components = null;

/// <summary>

/// Освободить все используемые ресурсы.

/// </summary>

/// <param name="disposing">истинно, если управляемый ресурс должен быть удален; иначе ложно.</param>

protected override void Dispose(bool disposing)

{ if (disposing && (components != null))

{ components.Dispose();

} base.Dispose(disposing);

}

#region Код, автоматически созданный конструктором форм Windows

/// <summary>

/// Обязательный метод для поддержки конструктора - не изменяйте

/// содержимое данного метода при помощи редактора кода.

/// </summary>

private void InitializeComponent()

{ this.button1 = new System.Windows.Forms.Button();

this.button2 = new System.Windows.Forms.Button();

this.comboBox1 = new System.Windows.Forms.ComboBox();

this.label1 = new System.Windows.Forms.Label();

this.label2 = new System.Windows.Forms.Label();

this.maskedTextBox1 = new System.Windows.Forms.MaskedTextBox();

this.label4 = new System.Windows.Forms.Label();

this.label5 = new System.Windows.Forms.Label();

this.label6 = new System.Windows.Forms.Label();

this.maskedTextBox2 = new System.Windows.Forms.MaskedTextBox();

this.maskedTextBox3 = new System.Windows.Forms.MaskedTextBox();

this.maskedTextBox4 = new System.Windows.Forms.MaskedTextBox();

this.maskedTextBox5 = new System.Windows.Forms.MaskedTextBox();

this.SuspendLayout();

// // button1

// this.button1.Location = new System.Drawing.Point(82, 152);

this.button1.Name = "button1";

this.button1.Size = new System.Drawing.Size(104, 35);

this.button1.TabIndex = 0;

this.button1.Text = "ОК";

this.button1.UseVisualStyleBackColor = true;

this.button1.Click += new System.EventHandler(this.button1_Click);

// // button2

// this.button2.Location = new System.Drawing.Point(269, 152);

this.button2.Name = "button2";

this.button2.Size = new System.Drawing.Size(116, 35);

this.button2.TabIndex = 1;

this.button2.Text = "Очистить";

this.button2.UseVisualStyleBackColor = true;

this.button2.Click += new System.EventHandler(this.button2_Click);

//

// comboBox1

// this.comboBox1.FormattingEnabled = true;

this.comboBox1.Items.AddRange(new object[] {

"двоичная",

"восьмиричная",

"десятичная",

"шестнадцатиричная"});

this.comboBox1.Location = new System.Drawing.Point(234, 94);

this.comboBox1.Name = "comboBox1";

this.comboBox1.Size = new System.Drawing.Size(151, 21);

this.comboBox1.TabIndex = 3;

this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged);

// // label1

// this.label1.AutoSize = true;

this.label1.Location = new System.Drawing.Point(47, 59);

this.label1.Name = "label1";

this.label1.Size = new System.Drawing.Size(81, 13);

this.label1.TabIndex = 4;

this.label1.Text = "Введите число";

// // label2

// this.label2.AutoSize = true;

this.label2.Location = new System.Drawing.Point(47, 94);

this.label2.Name = "label2";

this.label2.Size = new System.Drawing.Size(158, 13);

this.label2.TabIndex = 5;

this.label2.Text = "Выбирите систему счисления";

// // maskedTextBox1

// this.maskedTextBox1.Location = new System.Drawing.Point(234, 65);

this.maskedTextBox1.Name = "maskedTextBox1";

this.maskedTextBox1.Size = new System.Drawing.Size(151, 20);

this.maskedTextBox1.TabIndex = 6;

// // label3

// this.label3.AutoSize = true;

this.label3.Location = new System.Drawing.Point(58, 254);

this.label3.Name = "label3";

this.label3.Size = new System.Drawing.Size(54, 13);

this.label3.TabIndex = 7;

this.label3.Text = "двоичная";

// // label4

// this.label4.AutoSize = true;

this.label4.Location = new System.Drawing.Point(58, 306);

this.label4.Name = "label4";

this.label4.Size = new System.Drawing.Size(80, 13);

this.label4.TabIndex = 8;

this.label4.Text = "восьмиричная";

// this.label5.AutoSize = true;

this.label5.Location = new System.Drawing.Point(58, 356);

this.label5.Name = "label5";

this.label5.Size = new System.Drawing.Size(65, 13);

this.label5.TabIndex = 9;

this.label5.Text = "десятичная";

// // label6

// this.label6.AutoSize = true;

this.label6.Location = new System.Drawing.Point(58, 413);

this.label6.Name = "label6";

this.label6.Size = new System.Drawing.Size(108, 13);

this.label6.TabIndex = 10;

this.label6.Text = "шестнадцатиричная";

// // maskedTextBox2

// this.maskedTextBox2.Location = new System.Drawing.Point(192, 251);

this.maskedTextBox2.Name = "maskedTextBox2";

this.maskedTextBox2.Size = new System.Drawing.Size(129, 20);

this.maskedTextBox2.TabIndex = 12;

// // maskedTextBox3

// this.maskedTextBox3.Location = new System.Drawing.Point(192, 353);

this.maskedTextBox3.Name = "maskedTextBox3";

this.maskedTextBox3.Size = new System.Drawing.Size(129, 20);

this.maskedTextBox3.TabIndex = 13;

// // maskedTextBox4

// this.maskedTextBox4.Location = new System.Drawing.Point(192, 299);

this.maskedTextBox4.Name = "maskedTextBox4";

this.maskedTextBox4.Size = new System.Drawing.Size(129, 20);

this.maskedTextBox4.TabIndex = 14;

// // maskedTextBox5

// this.maskedTextBox5.Location = new System.Drawing.Point(192, 406);

this.maskedTextBox5.Name = "maskedTextBox5";

this.maskedTextBox5.Size = new System.Drawing.Size(129, 20);

this.maskedTextBox5.TabIndex = 15;

// // Form1

// this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

this.ClientSize = new System.Drawing.Size(560, 456);

this.Controls.Add(this.maskedTextBox5);

this.Controls.Add(this.maskedTextBox4);

this.Controls.Add(this.maskedTextBox3);

this.Controls.Add(this.maskedTextBox2);

this.Controls.Add(this.label6);

this.Controls.Add(this.label5);

this.Controls.Add(this.label4);

this.Controls.Add(this.label3);

this.Controls.Add(this.maskedTextBox1);

this.Controls.Add(this.label2);

this.Controls.Add(this.label1);

this.Controls.Add(this.comboBox1);

this.Controls.Add(this.button2);

this.Controls.Add(this.button1);

this.Name = "Form1";

this.Text = "перевод числа в различных системах счисления";

this.Load += new System.EventHandler(this.Form1_Load);

this.ResumeLayout(false);

this.PerformLayout();

}

#endregion

private System.Windows.Forms.Button button1;

private System.Windows.Forms.Button button2;

private System.Windows.Forms.ComboBox comboBox1;

private System.Windows.Forms.Label label1;

private System.Windows.Forms.Label label2;

private System.Windows.Forms.MaskedTextBox maskedTextBox1;

private System.Windows.Forms.Label label3;

private System.Windows.Forms.Label label4;

private System.Windows.Forms.Label label5;

private System.Windows.Forms.Label label6;

private System.Windows.Forms.MaskedTextBox maskedTextBox2;

private System.Windows.Forms.MaskedTextBox maskedTextBox3;

private System.Windows.Forms.MaskedTextBox maskedTextBox5;

}}