Last active
January 9, 2019 13:12
-
-
Save sukov/2decc775db97d7231252cc8bc9a5cdd2 to your computer and use it in GitHub Desktop.
Byte, Short Swift
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
import Foundation | |
extension Character { | |
var byte: UInt8 { | |
return String(self).utf8.map{UInt8($0)}[0] | |
} | |
var short: UInt16 { | |
return String(self).utf16.map{UInt16($0)}[0] | |
} | |
} | |
extension Sequence where Element == Character { // Same as String | |
var byteArray: [UInt8] { | |
return String(self).utf8.map{UInt8($0)} | |
} | |
var shortArray: [UInt16] { | |
return String(self).utf16.map{UInt16($0)} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment