Created
August 18, 2020 16:39
-
-
Save jaekong/241ede4391ab55c0f5ea22bbbcfb42ef to your computer and use it in GitHub Desktop.
Small Swift extension for getting proper binary representation of UInt8.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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