I am taking in a hexadecimal value and converting it into a binary number however, it is not printing out the leading zeros. I know that swift does not have a built in ability to do so like C. I am wondering if there is a way to print out any leading zeros when I know that the biggest the binary number will be is 16 characters. I have some code that runs for me by taking the hex number, converting it into a decimal number, and then into a binary number.
@IBAction func HextoBinary(_ sender: Any)
{
//Removes all white space and recognizes only text
let origHex = textView.text.trimmingCharacters(in: .whitespacesAndNewlines)
if let hexNumb_int = Int(origHex, radix:16)
{
let decNumb_str = String(hexNumb_int, radix:2)
textView.text = decNumb_str
}
}
Any assistance is greatly appreciated.