[Slightly OT] Integers smarter than me today

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[Slightly OT] Integers smarter than me today

Schwab,Wilhelm K
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
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: [Slightly OT] Integers smarter than me today

dpharris
Assuming these are 12bit signed numbers, then I think the answer is that you
should extend the 12th bit out to the 16th bit position.  The conversion should
be 0..2047 (0x000..0x7FF) => 0..2047, and 0x4095..0x2048 (0xFFF..0x800) =>
-1..-2048.   So, it is probably easier to keep the numbers less than 2096, and
for those those bigger than 2047, subtract them from 4096 and negate.  

David


Quoting "Schwab,Wilhelm K" <[hidden email]>:

> 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
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>





_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: [Slightly OT] Integers smarter than me today

Schwab,Wilhelm K
David,

I will try your test, subtract+negate algorithm.

On extending the highest bit, what is the reason for stopping at 16?   I thought of something similar, but assumed I should cover all bits used in representing a small integer??

Bill



-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of [hidden email]
Sent: Thursday, February 11, 2010 8:00 PM
To: [hidden email]
Subject: Re: [Pharo-project] [Slightly OT] Integers smarter than me today

Assuming these are 12bit signed numbers, then I think the answer is that you should extend the 12th bit out to the 16th bit position.  The conversion should be 0..2047 (0x000..0x7FF) => 0..2047, and 0x4095..0x2048 (0xFFF..0x800) =>
-1..-2048.   So, it is probably easier to keep the numbers less than 2096, and
for those those bigger than 2047, subtract them from 4096 and negate.  

David


Quoting "Schwab,Wilhelm K" <[hidden email]>:

> 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
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>





_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: [Slightly OT] Integers smarter than me today

Matthias Berth-2
In reply to this post by Schwab,Wilhelm K
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
<[hidden email]> 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
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
Reply | Threaded
Open this post in threaded view
|

Re: [Slightly OT] Integers smarter than me today

Schwab,Wilhelm K
Thanks for bringing this up - yes,  David's(??) suggestion did the trick.  Beyond that, the key to figuring it out was making dot plots of the data stream so I could see the patterns.  There is still an unresolved question or two, but I appear to be getting data, and "the monkey on on their back" as a friend of mine would say.

Bill



-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Matthias Berth
Sent: Wednesday, February 17, 2010 3:42 PM
To: [hidden email]
Subject: Re: [Pharo-project] [Slightly OT] Integers smarter than me today

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 <[hidden email]> 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
> [hidden email]
> http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
>

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project