Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
BCD16BitTest
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static Dictionary<string, string> myDict = new Dictionary<string, string> { { "0", "0000" }, { "1", "0001" }, { "2", "0010" }, { "3", "0011" }, { "4", "0100" }, { "5", "0101" }, { "6", "0110" }, { "7", "0111" }, { "8", "1000" }, { "9", "1001" }, }; public static void Main(string[] args) { //Your code goes here Random rnd = new Random(); var originalValue = rnd.Next(0, 999); Console.WriteLine((ushort)originalValue); var bcdstring = GetBDCString((ushort)originalValue); Console.WriteLine(bcdstring); var decimalFromBCDasBinary = GetDecimalfromBinary(bcdstring); Console.WriteLine(decimalFromBCDasBinary); var returnOriginalValue = ConvertShort2BCD16(decimalFromBCDasBinary, false); Console.WriteLine(returnOriginalValue); } public static string GetBDCString (ushort variable) { string stringValue = string.Empty; foreach (char c in variable.ToString()) { stringValue += myDict[c.ToString()]; } return stringValue; } public static ushort GetDecimalfromBinary (string newValue) { return (ushort)Convert.ToInt32(newValue, 2); } public static double ConvertShort2BCD16(ushort value, bool byteSwap) { var bcdValue = Convert.ToString(value, 2); ushort decimalFromBCD = ushort.Parse(Convert.ToInt32(bcdValue, 2).ToString("X")); return BitConverter.ToInt16(BitConverter.GetBytes(decimalFromBCD), 0); } } }
run
|
edit
|
history
|
help
0
saxasdcdf
Project01
Delegate & anonymous method
Project Euler No 2
Main 5.4
A2Z Dice Roll
learning1
Prime no for specified max no by user(Using While Loop)
myPractice
Problem_fb_series