[Pharo-project] [Slightly OT] Integers smarter than me today

Matthias Berth matthias.berth at googlemail.com
Wed Feb 17 15:41:56 EST 2010


I guess your problem is already solved, but I could not resist ;)

So you have 2^12 = 4096 possible 16 bit words? May I suggest a brute
force solution? Make an Array with 2^16 entries to do the translation
from 16 bit words to signed values like this:

  signedValue := translationArray at: word

You can make a small script to fill the array. The advantage is that
you can check the array's contents to see if you are doing the right
thing. If your 2s complement theory should not work out then it is
easy to change.

HTH

Matthias

On Thu, Feb 11, 2010 at 10:53 PM, Schwab,Wilhelm K
<bschwab at anest.ufl.edu> wrote:
> Hello all,
>
> I am trying to make a recognizer for a communication protocol that has very likely been errantly documented.  Such tasks can be difficult enough with good docs, but I'm not even sure what is supposed to be happening, so it is really interesting.
>
> One of the things that I **think** is happening, is that 12-bit two's complement data is included at one point in the stream.  The bits are spread over a 16 bit word.  Let's assume that I can correctly gather the 12 bits together.  Could some kind soul suggest how to go from the resulting SmallInteger to the correct signed value?  Smalltalk is adding a wrinkle that I am not sure how to handle: should I set the "missing" bits to 1?  Out to bit 31?
>
> Any pointers/suggestions would be greatly appreciated.
>
> Bill
>
> _______________________________________________
> Pharo-project mailing list
> Pharo-project at lists.gforge.inria.fr
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>




More information about the Pharo-dev mailing list