Created
April 9, 2020 07:03
-
-
Save ctreffs/1efcb91d3d1460dcbd8bfe35488bbbe7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 BinaryInteger { | |
/// Provides a padded binary representation of this value (i.e. 01001001). | |
public var binaryDescription: String { | |
let str = String(self, radix: 2) | |
return String(repeatElement("0", count: (MemoryLayout<Self>.stride * 8) - str.utf8.count)) + str | |
} | |
} | |
extension OptionSet where RawValue: BinaryInteger { | |
/// Provides a padded binary representation of this value (i.e. 01001001). | |
public var binaryDescription: String { | |
return rawValue.binaryDescription | |
} | |
} | |
extension RawRepresentable where RawValue: BinaryInteger { | |
/// Provides a padded binary representation of this value (i.e. 01001001). | |
public var binaryDescription: String { | |
return rawValue.binaryDescription | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment