/// <summary> /// convert the binary value of the address to equivalent hexadecimal value /// </summary> /// <param name="address"></param> /// <returns></returns> private string BinaryToHexadecimal(string address) { string tempAddress = ""; if (!string.IsNullOrEmpty(address)) { if (address.Length % 4 != 0) { int closestFourMultiple = 4 * (address.Length / 4 + 1); address = address.PadLeft(closestFourMultiple, '0'); } int subStringBegining = 0; string subStringHolder; while (subStringBegining < address.Length) { //change each four characters -represinting binary values- to their hexadecimal equvlant subStringHolder = address.Substring(subStringBegining, 4); tempAddress += ValueConverterModel.GetHexadecimalValue(subStringHolder); subStringBegining += 4; } return(tempAddress); } else { return(null); } }
/// <summary> /// convert the hexadecimal value of the address to equivalent binary value /// </summary> /// <param name="address"></param> /// <returns></returns> private string HexadecimalToBinary(string address) { string tempAddress = ""; if (!string.IsNullOrEmpty(address)) { address = address.ToLower(); for (int i = address.Length - 1; i >= 0; i--) { tempAddress += ValueConverterModel.GetHexadecimalValue(address[i].ToString()); } address = ""; int subStringEnding = tempAddress.Length; while (subStringEnding >= 4) { address += tempAddress.Substring(subStringEnding - 4, 4); subStringEnding -= 4; } return(address); } else { return(null); } }