<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><p style="margin: 0.0px 0.0px 1.0px 56.0px; text-indent: -56.0px; font: 12.0px Helvetica"><b><span class="Apple-style-span" style="font-weight: normal; ">Hi,<div><br class="webkit-block-placeholder"></div><div>I have to parse the following byte sequence where the first byte indicates the payload length if the </div><div>payload length in 15 bytes or less, e.g. the 3 byte payload</div><div><br class="webkit-block-placeholder"></div><div>x01 x02 x03</div><div><br class="webkit-block-placeholder"></div><div>will be encoded as</div><div><br class="webkit-block-placeholder"></div><div>0x23 x01 x02 x03</div><div><br class="webkit-block-placeholder"></div><div>with 0x23 - 0x20 = 3, the length of the payload.</div><div><br class="webkit-block-placeholder"></div><div>So when I parse it, I'd like to use a bit syntax similar to following:</div><div><br class="webkit-block-placeholder"></div><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica" size="3">decode</font></font><span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica" size="3">(<< </font></font></span><span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica" size="3">Len</font></font></span><span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica" size="3">:</font></font></span><span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica" size="3">8</font></font></span><span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica" size="3">/</font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica" size="3">unsigned</font></font><span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica" size="3">, </font></font></span><span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica" size="3">Rest</font></font></span><span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica" size="3">:(</font></font></span><span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica" size="3">Len</font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica" size="3"> </font></font><span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica" size="3">-</font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica" size="3"> 16#20</font></font><span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica" size="3">)/</font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica" size="3">unsigned</font></font><span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica" size="3">>>)</font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica" size="3"> </font></font><span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica" size="3">-></font></font></span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica" size="3"> </font></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica" size="3"><span class="Apple-tab-span" style="white-space: pre; "> </span><<</font></font></span><span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica" size="3">Rest</font></font></span><span><font class="Apple-style-span" color="#000000"><font class="Apple-style-span" face="Helvetica" size="3">>>.</font></font></span></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Helvetica" size="3"><br class="webkit-block-placeholder"></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Helvetica" size="3">But this is an illegal bit size.</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Helvetica" size="3"><br class="webkit-block-placeholder"></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Helvetica" size="3">Is there an elegant way around this?</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Helvetica" size="3"><br class="webkit-block-placeholder"></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Helvetica" size="3">Thx,</font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Helvetica" size="3"><br class="webkit-block-placeholder"></font></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 11px/normal Monaco; "><font class="Apple-style-span" face="Helvetica" size="3">Ben</font></div></div></span></b></p></body></html>