comp.lang.ada
 help / color / mirror / Atom feed
From: beser@tron.UUCP (Eric Beser)
Subject: Re: Question with setting sign bit
Date: 13 Dec 90 12:35:20 GMT	[thread overview]
Message-ID: <679@tron.UUCP> (raw)
In-Reply-To: 18172@hydra.gatech.EDU


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
 

       reply	other threads:[~1990-12-13 12:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <18172@hydra.gatech.EDU>
1990-12-13 12:35 ` Eric Beser [this message]
1990-12-06 13:12 Question with setting sign bit Jim West (Stealth Contractor)
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox