From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_05,INVALID_DATE, MSGID_SHORT autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!sdd.hp.com!wuarchive!uunet!tron!beser From: beser@tron.UUCP (Eric Beser) Newsgroups: comp.lang.ada Subject: Re: Question with setting sign bit Summary: setting the sign bit Message-ID: <679@tron.UUCP> Date: 13 Dec 90 12:35:20 GMT References: <18172@hydra.gatech.EDU> Distribution: usa Organization: Westinghouse Electronic Systems Group, Baltimore, MD, USA List-Id: The sign bit on a system that does not support unsigned arithmetic can be a "sticky" situation. However, where you are just checking a single bit, the solution is pretty easy. declare type bit_array_32 is array (0 .. 31) of boolean; pragma pack(bit_array_32); function to_bit_array_32 is new unchecked_conversion (source => integer, target => bit_array_32); function to_integer is new unchecked_conversion (source => bit_array_32, target => integer); check_word : bit_array_32; begin check_word := to_bit_array_32(function_reading_integer); if check_word(31) then -- sign bit set -- do what you have to end if; end this may be turned into an inline function that returns boolean, in which case it would look like function is_sign_bit_set (on_the_integer : integer) return boolean is same declarations as above with the exception check_word : bit_array_32 := to_bit_array_32(on_the_integer); begin return check_word(31); end is sign_bit_set; pragma inline (is_sign_bit_set); if speed is a requirement, and your compiler supports it, use machine code inserted procedures (within the ada function) and pragma inline that. On the XD 1750a compiler, we can do that in about 3 lines of code. Hope this helps Eric Beser Senior Ada Technologist Westinghouse Electronic Systems Group (301) - 765 - 1010 ebeser@ajpo.sei.cmu.edu