Hello everyone
I am looking for an alternative Swift method to PHP pack()
method to return the same value for this code line
echo pack('H*', sprintf("%02X",1));
Based on w3schools
echo base64_encode(pack('H*', sprintf("%02X",1)));
prints AQ==
and
echo base64_encode(sprintf("%02X",1));
prints MDE=
I made some changes to @OOPer class and it worked for me.
public class MyTag {
public let tag: UInt8
public let value: String
public init(tag: UInt8, value: String) {
self.tag = tag
assert(value.utf8.count < 256, "The length of `value` needs to be less than 256.")
self.value = value
}
public var length: UInt8 { UInt8(value.utf8.count) }
public var tlv: [UInt8] { return ([tag, length] + [UInt8](value.utf8)) }
}
Thank you @OOPer for your help!