Skip to content

Instantly share code, notes, and snippets.

@jaekong
Created August 18, 2020 16:39
Show Gist options
  • Save jaekong/241ede4391ab55c0f5ea22bbbcfb42ef to your computer and use it in GitHub Desktop.
Save jaekong/241ede4391ab55c0f5ea22bbbcfb42ef to your computer and use it in GitHub Desktop.
Small Swift extension for getting proper binary representation of UInt8.
extension UInt8 {
var binaryRepresentation: String {
get {
let number = String(self, radix: 2)
let padding = String(repeating: "0", count: leadingZeroBitCount)
return String(padding + number)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment