Exemple #1
0
        private void convertNumber(object sender, EventArgs e)
        {
            IEEE754 patternIEEE = new IEEE754();

            valueOne.Text = !string.IsNullOrEmpty(valueOne.Text) ? valueOne.Text.Replace(".", ",") : "0";
            valueTwo.Text = !string.IsNullOrEmpty(valueTwo.Text) ? valueTwo.Text.Replace(".", ",") : "0";
            string nBin1 = patternIEEE.FloatToBinary(float.Parse(valueOne.Text));
            string nBin2 = patternIEEE.FloatToBinary(float.Parse(valueTwo.Text));

            string[] result1 = nBin1.Split(' ');
            signalBit1.Text = result1[0];
            expoente1.Text  = result1[1];
            fracao1.Text    = result1[2];
            string[] result2 = nBin2.Split(' ');
            signalBit2.Text = result2[0];
            expoente2.Text  = result2[1];
            fracao2.Text    = result2[2];
            // int integerPart1 = int.Parse(valueOne.Text.Split(',')[0]);
            // int integerPart2 = int.Parse(valueTwo.Text.Split(',')[0]);
            // string integerPart1Bin = Convert.ToString(integerPart1, 2);
            // string integerPart2Bin = Convert.ToString(integerPart2, 2);

            string n1Hex = patternIEEE.BinaryToHex(nBin1);
            string n2Hex = patternIEEE.BinaryToHex(nBin2);

            //dividir o numero de 24 bits em 6 partes e transformar cada grupo de 4 bits para hexa
            valueOneHex.Text = "0x" + n1Hex.ToUpper();
            valueTwoHex.Text = "0x" + n2Hex.ToUpper();
        }
Exemple #2
0
        private void setResultFields(string binResult)
        {
            IEEE754 patternIEEE = new IEEE754();

            signalResult.Text  = binResult.Substring(0, 1);
            expoentResult.Text = binResult.Substring(1, 8);
            fracaoResult.Text  = binResult.Substring(9, 23);
            string n1Hex = patternIEEE.BinaryToHex(binResult);

            hexResult.Text   = "0x" + n1Hex.ToUpper();
            floatResult.Text = patternIEEE.hexToFloat(n1Hex).ToString();
        }