KONU : C Sharp ( C# ) Form uygulamalar gray kodu ikilik tabana çevirme programı, gray code to binary code convertion application.
UYGULAMAYI İNDİR
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace gray_code_binary_convertion_10_bit
{
public partial class Form1 : Form
{
long[] grayTable;
int nmax = 9, n = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//Birinci Yöntem :
grayTable = new long[1 << (nmax + 1)];
grayTable[0] = 0;
grayTable[1] = 1;
n = 1;
for (int i = 0; i < nmax; i++)
{
for (int j = 0; j < (1 << n); j++)
{
grayTable[(1 << n) + j] = grayTable[(1 << n) - j - 1] | 1 << n;
}
n++;
}
lstBinaryTable.Items.Clear();
for (int i = 0; i < (1 << (nmax + 1)); i++)
{
lstBinaryTable.Items.Add(Convert.ToString(grayTable[i], 2));
}
}
private void btnConvert_Click(object sender, EventArgs e)
{
//İkinci Yöntem :
UInt32 grayData = 0;
UInt32 cevrilen_sayi = 0;
UInt32 onluk_taban = 0;
try
{
cevrilen_sayi = Convert.ToUInt32(txtGrayCode.Text);
for (double i = 0; i < txtGrayCode.Text.Trim().Length; i++)
{
onluk_taban += (cevrilen_sayi % 10) * (UInt32)Math.Pow(2, i);//son basamağı al ve onluk tabanda, değere ekle
cevrilen_sayi /= 10;//bir basamak sola kay
}
grayData = onluk_taban;
}
catch (Exception)
{
}
UInt32 binaryData = (grayData >> 1) ^ grayData;
txtBinaryCode.Text = Convert.ToString(Math.Abs(binaryData), 2);
}
}
}

Hiç yorum yok :
Yorum Gönder