Thank you Nicolas! &nbsp;If you send me a method with your date stamp on it it&#39;ll get integrated in my changes...<br><br><div class="gmail_quote">On Fri, Jul 4, 2008 at 1:22 PM, nicolas cellier &lt;<a href="mailto:ncellier@ifrance.com">ncellier@ifrance.com</a>&gt; wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
Hello VM gods,<br>
every little improvment counts, so my 2 pennies:<br>
<br>
Interpreter&gt;&gt;byteSwapped: w<br>
 &nbsp;&quot;Answer the given integer with its bytes in the reverse order.&quot;<br>
<br>
 &nbsp;BytesPerWord = 4<br>
 &nbsp;ifTrue:<br>
 &nbsp; &nbsp;[^((w bitShift: Byte3ShiftNegated) bitAnd: Byte0Mask)<br>
 &nbsp; &nbsp;+ ((w bitShift: Byte1ShiftNegated) bitAnd: Byte1Mask)<br>
 &nbsp; &nbsp;+ ((w bitShift: Byte1Shift &nbsp; &nbsp; &nbsp; &nbsp; ) bitAnd: Byte2Mask)<br>
 &nbsp; &nbsp;+ ((w bitShift: Byte3Shift &nbsp; &nbsp; &nbsp; &nbsp; ) bitAnd: Byte3Mask)]<br>
 &nbsp;ifFalse:<br>
 &nbsp; &nbsp;[^((w bitShift: Byte7ShiftNegated) bitAnd: Byte0Mask)<br>
 &nbsp; &nbsp;+ ((w bitShift: Byte5ShiftNegated) bitAnd: Byte1Mask)<br>
 &nbsp; &nbsp;+ ((w bitShift: Byte3ShiftNegated) bitAnd: Byte2Mask)<br>
 &nbsp; &nbsp;+ ((w bitShift: Byte1ShiftNegated) bitAnd: Byte3Mask)<br>
 &nbsp; &nbsp;+ ((w bitShift: Byte1Shift &nbsp; &nbsp; &nbsp; &nbsp; ) bitAnd: Byte4Mask)<br>
 &nbsp; &nbsp;+ ((w bitShift: Byte3Shift &nbsp; &nbsp; &nbsp; &nbsp; ) bitAnd: Byte5Mask)<br>
 &nbsp; &nbsp;+ ((w bitShift: Byte5Shift &nbsp; &nbsp; &nbsp; &nbsp; ) bitAnd: Byte6Mask)<br>
 &nbsp; &nbsp;+ ((w bitShift: Byte7Shift &nbsp; &nbsp; &nbsp; &nbsp; ) bitAnd: Byte7Mask)]<br>
<br>
<br>
Can be written with less operations with the classical:<br>
<br>
byteSwapped: w<br>
 &nbsp;| x |<br>
 &nbsp;x := w.<br>
 &nbsp;BytesPerWord = 4<br>
 &nbsp; &nbsp;ifTrue: [<br>
 &nbsp; &nbsp; &nbsp;&quot;Note: In C, x unsigned 64 bits, first bitAnd: is not required&quot;<br>
 &nbsp; &nbsp; &nbsp;x = ((x bitAnd: 16rFFFF0000 &gt;&gt; 16)<br>
 &nbsp; &nbsp; &nbsp; &nbsp;+ ((x bitAnd: 16r0000FFFF &lt;&lt; 16).<br>
 &nbsp; &nbsp; &nbsp;x = ((x bitAnd: 16rFF00FF00 &gt;&gt; 8)<br>
 &nbsp; &nbsp; &nbsp; &nbsp;+ ((x bitAnd: 16r00FF00FF &lt;&lt; 8)]<br>
 &nbsp; &nbsp;ifFalse: [<br>
 &nbsp; &nbsp; &nbsp;&quot;Note: In C, x unsigned 64 bits, first bitAnd: is not required&quot;<br>
 &nbsp; &nbsp; &nbsp;x = ((x bitAnd: 16rFFFFFFFF00000000 &gt;&gt; 32)<br>
 &nbsp; &nbsp; &nbsp; &nbsp;+ ((x bitAnd: 16r00000000FFFFFFFF &lt;&lt; 32).<br>
 &nbsp; &nbsp; &nbsp;x = ((x bitAnd: 16rFFFF0000FFFF0000 &gt;&gt; 16)<br>
 &nbsp; &nbsp; &nbsp; &nbsp;+ ((x bitAnd: 16r0000FFFF0000FFFF &lt;&lt; 16).<br>
 &nbsp; &nbsp; &nbsp;x = ((x bitAnd: 16rFF00FF00FF00FF00 &gt;&gt; 8)<br>
 &nbsp; &nbsp; &nbsp; &nbsp;+ ((x bitAnd: 16r00FF00FF00FF00FF &lt;&lt; 8)].<br>
 &nbsp;^x<br>
<br>
Yeah, the cost is (BytesPerWord log: 2).<br>
Of course, you can use named constants, with proper unsigned long declarations, that&#39;s a detail i let you deal with.<br><font color="#888888">
<br>
Nicolas<br>
<br>
<br>
</font></blockquote></div><br>