public void Convert_test_1() { var dtob = new DecimalToHex(); var result = dtob.Convert(4); Assert.AreEqual(result, "4"); }
public void AddressCreateTagBitHex(DataBlock db, int Address, int Save_BufAddr, bool IsNew) { int hex1 = 0; if (IsNew == false) { db.Tags.Clear(); } foreach (DataBlock item in dv.DataBlocks) { TagsCount += item.Tags.Count; if (db != null) { if (db.DataBlockName.Equals(item.DataBlockName)) { break; } } } if (chkCreateTag.Checked) { int y = Address; hex1 = (int)HexadecimalToDecimal.HexToDec(Address.ToString()); for (int i = Address; i < Save_BufAddr + y; i++) { string hexaNumber = string.Empty; Tag tg = new Tag() { TagId = IDX += 1 }; if (hex1 == 0) { hexaNumber = "0"; } else { hexaNumber = DecimalToHex.GetDecimalToHex(long.Parse(hex1.ToString())); } tg.ChannelId = int.Parse(txtChannelId.Text); tg.DeviceId = int.Parse(txtDeviceId.Text); tg.DataBlockId = int.Parse(txtDataBlockId.Text); tg.TagName = $"TAG{TagsCount:d5}"; tg.Address = $"{txtDomain.Text}{hexaNumber}"; tg.Description = $"{txtDesc.Text} {i.ToString("X")}"; tg.DataType = (DataTypes)System.Enum.Parse(typeof(DataTypes), cboxDataType.SelectedItem.ToString()); db.Tags.Add(tg); hex1 += 1; TagsCount += 1; } } }
static void Main(string[] args) { //input long N = long.Parse(Console.ReadLine()); //logic long current; string result = ""; for (long i = 0; N > 0; i++, N = N / 16) { current = (N % 16); switch (current) { case 10: result = result + "A"; continue; case 11: result = result + "B"; continue; case 12: result = result + "C"; continue; case 13: result = result + "D"; continue; case 14: result = result + "E"; continue; case 15: result = result + "F"; continue; default: result = result + current.ToString(); continue; } if (N < 16) { break; } } //output Console.WriteLine(DecimalToHex.ReverseString(result)); }