public static string HexToDec(string value, bool isAddress) { //Check if valid syntax of a hex address if (CheckSyntax.Int64Value(value, true)) { value = Conversions.HexToUInt64(value).ToString(); } //Return updated string return(value); }
//Converts to 8 digit address format public static string ToAddress(string value) { if (CheckSyntax.Int32Value(value, false)) { return(String.Format("{0:X8}", Convert.ToUInt32(value))); } else if (CheckSyntax.Int64Value(value, false)) { return(String.Format("{0:X16}", Convert.ToUInt64(value))); } else { return("??"); } }
private void acceptButton_Click(object sender, EventArgs e) { string ValueString = ValueTextBox.Text; switch (ScanType) { case ScanDataType.Binary: if (CheckSyntax.BinaryValue(ValueString)) { Value = Conversions.ToUnsigned(ValueString, ScanType); } else { failed = true; } break; case ScanDataType.Byte: //Check syntax if (CheckSyntax.ByteValue(ValueString, IsHexCB.Checked)) { if (!IsHexCB.Checked) { //Take unsigned value Value = Conversions.ToUnsigned(ValueString, ScanType); } else //Take unsigned value after converting it from hex { Value = Conversions.ToUnsigned(Conversions.HexToByte(ValueString).ToString(), ScanType); } } else //Invalid syntax { failed = true; } break; case ScanDataType.Int16: if (CheckSyntax.Int32Value(ValueString, IsHexCB.Checked)) { if (!IsHexCB.Checked) { Value = Conversions.ToUnsigned(ValueString, ScanType); } else { Value = Conversions.ToUnsigned(Conversions.HexToShort(ValueString).ToString(), ScanType); } } else { failed = true; } break; case ScanDataType.Int32: if (CheckSyntax.Int32Value(ValueString, IsHexCB.Checked)) { if (!IsHexCB.Checked) { Value = Conversions.ToUnsigned(ValueString, ScanType); } else { Value = Conversions.ToUnsigned(Conversions.HexToInt(ValueString).ToString(), ScanType); } } else { failed = true; } break; case ScanDataType.Int64: if (CheckSyntax.Int64Value(ValueString, IsHexCB.Checked)) { if (!IsHexCB.Checked) { Value = Conversions.ToUnsigned(ValueString, ScanType); } else { Value = Conversions.ToUnsigned(Conversions.HexToUInt64(ValueString).ToString(), ScanType); } } else { failed = true; } break; case ScanDataType.Single: if (CheckSyntax.SingleValue(ValueString, IsHexCB.Checked)) { if (!IsHexCB.Checked) { Value = Conversions.ToUnsigned(ValueString, ScanType); } else { Value = Conversions.ToUnsigned(Conversions.HexToSingle(ValueString).ToString(), ScanType); } } else { failed = true; } break; case ScanDataType.Double: if (CheckSyntax.DoubleValue(ValueString, IsHexCB.Checked)) { if (!IsHexCB.Checked) { Value = Conversions.ToUnsigned(ValueString, ScanType); } else { Value = Conversions.ToUnsigned(Conversions.HexToDouble(ValueString).ToString(), ScanType); } } else { failed = true; } break; case ScanDataType.Text: //TODO: everything Value = ValueString; break; } if (failed) { MessageBox.Show("Invalid value format.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }