Andrew C. Oliver wrote:

>Hi all,
>
>I've been thinking about it and I just hate the idea of making all
>shorts ints to handle signing issues.  So how about this.  Add a utility
>function somewhere called ushort that takes in a short and outputs an
>int adjusting the value by reinterpreting the sign as a proper value. 
>Yes this will waste an operation but binary operations are not very
>expensive.  
>
>Anyhow.  Heres what I think it is roughtly
>
>int retval = myshort;
>if (myshort < 0) {
>       retval = (Math.abs(myshort));
>       retval = retval |  0x800;
>}
>return retval;
>
>Please correct me if I'm wrong and MARC can you give us the handy dandy
>bit-twiddler version?
>
>Will this work?
>
>We should have the method in a central util class, but then have (for
>convenience) a method called ushort that calls to it in either the
>stylesheet for generating records/types or a superclass.
>
>Thoughts?
>
>-andy
>
    static int ushort(short s)
    {
    int rval = s;
    if (s < 0)
    {
        rval = 65536 + s;
    }
    return rval;
    }

That's all you need. I've already tested it.


Reply via email to