<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Thanks Ole, that’s definitely nicer, I’ve updated my code!<div class=""><br class=""></div><div class="">Still not exactly ergonomic though :-)</div><div class=""><div class=""><br class=""></div><div class="">-Chris</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 11, 2018, at 3:28 AM, Ole Begemann via swift-dev <<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="Singleton" style="word-wrap: break-word; -webkit-nbsp-mode: space;"><div class=""><br class="Apple-interchange-newline"><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"></div><div class="">In this particular example, you can use<span class="Apple-converted-space"> </span><font face="Menlo" class="">UInt8.init(ascii:)</font><span class="Apple-converted-space"> </span>to make it a little nicer (no need for the<span class="Apple-converted-space"> </span><font face="Menlo" class="">charToByte</font><span class="Apple-converted-space"> </span>function):</div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);"> <span class="" style="color: rgb(186, 45, 162);">func</span><span class="Apple-converted-space"> </span>hexToInt(<span class="" style="color: rgb(186, 45, 162);">_</span><span class="Apple-converted-space"> </span>c :<span class="Apple-converted-space"> </span><span class="" style="color: rgb(112, 61, 170);">UInt8</span>) -><span class="Apple-converted-space"> </span><span class="" style="color: rgb(112, 61, 170);">UInt8</span><span class="Apple-converted-space"> </span>{</div><div class="" style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);"> <span class="Apple-converted-space"> </span><span class="" style="color: rgb(186, 45, 162);">switch</span><span class="Apple-converted-space"> </span>c {</div><div class="" style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);"> <span class="Apple-converted-space"> </span><span class="" style="color: rgb(186, 45, 162);">case</span><span class="Apple-converted-space"> </span><span class="" style="color: rgb(112, 61, 170);">UInt8</span>(ascii:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(209, 47, 27);">"0"</span>)...<span class="" style="color: rgb(112, 61, 170);">UInt8</span>(ascii:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(209, 47, 27);">"9"</span>):</div><div class="" style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);"> <span class="Apple-converted-space"> </span><span class="" style="color: rgb(186, 45, 162);">return</span><span class="Apple-converted-space"> </span>c -<span class="Apple-converted-space"> </span><span class="" style="color: rgb(112, 61, 170);">UInt8</span>(ascii:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(209, 47, 27);">"0"</span>)</div><div class="" style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);"> <span class="Apple-converted-space"> </span><span class="" style="color: rgb(186, 45, 162);">case</span><span class="Apple-converted-space"> </span><span class="" style="color: rgb(112, 61, 170);">UInt8</span>(ascii:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(209, 47, 27);">"a"</span>)...<span class="" style="color: rgb(112, 61, 170);">UInt8</span>(ascii:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(209, 47, 27);">"f"</span>):</div><div class="" style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);"> <span class="Apple-converted-space"> </span><span class="" style="color: rgb(186, 45, 162);">return</span><span class="Apple-converted-space"> </span>c -<span class="Apple-converted-space"> </span><span class="" style="color: rgb(112, 61, 170);">UInt8</span>(ascii:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(209, 47, 27);">"a"</span>) +<span class="Apple-converted-space"> </span><span class="" style="color: rgb(39, 42, 216);">10</span></div><div class="" style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);"> <span class="Apple-converted-space"> </span><span class="" style="color: rgb(186, 45, 162);">case</span><span class="Apple-converted-space"> </span><span class="" style="color: rgb(112, 61, 170);">UInt8</span>(ascii:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(209, 47, 27);">"A"</span>)...<span class="" style="color: rgb(112, 61, 170);">UInt8</span>(ascii:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(209, 47, 27);">"F"</span>):</div><div class="" style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);"> <span class="Apple-converted-space"> </span><span class="" style="color: rgb(186, 45, 162);">return</span><span class="Apple-converted-space"> </span>c -<span class="Apple-converted-space"> </span><span class="" style="color: rgb(112, 61, 170);">UInt8</span>(ascii:<span class="Apple-converted-space"> </span><span class="" style="color: rgb(209, 47, 27);">"A"</span>) +<span class="Apple-converted-space"> </span><span class="" style="color: rgb(39, 42, 216);">10</span></div><div class="" style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27); background-color: rgb(255, 255, 255);"><span class="" style=""> <span class="Apple-converted-space"> </span></span><span class="" style="color: rgb(186, 45, 162);">default</span><span class="" style="">:<span class="Apple-converted-space"> </span></span><span class="" style="color: rgb(62, 30, 129);">fatalError</span><span class="" style="">(</span>"invalid hexadecimal character"<span class="" style="">)</span></div><div class="" style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);"> }</div><div class="" style="margin: 0px; font-stretch: normal; font-size: 13px; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);"> }</div></div></div></div></blockquote></div><br class=""></div></div></body></html>