Thread: xor
View Single Post
  #4 (permalink)  
Old 03-25-2012, 03:16 PM
Michael Moeller
Guest
 
Posts: n/a
Default Re: xor

Thank you for your quick answer.

Can I use Unsigned_Byte_T to read in a byte from a file
as in C? I haven't looked into this yet.

Regards,
Michael



On Sun, 25 Mar 2012, Niklas Holsti wrote:

> On 12-03-25 17:28 , Michael Moeller wrote:
>> Hi,
>>
>> I'm wondering what this code in C looks like translated to Ada:
>>
>> unsigned char x, y, z;
>> ...
>> z = x ^ y;
>> ...
>>
>> Oddly enough, none of the manuals I have covers simple numerical
>> xor of two numbers stored in variables.

>
> Use a modular integer type to get the XOR operation:
>
> -- begin example
> procedure Show_Xor
> is
> type Unsigned_Byte_T is mod 256;
> x, y, z : Unsigned_Byte_T;
> begin
> x := 26;
> y := 33;
> z := x xor y;
> end Show_Xor;
> --end example
>
>
> If you also want shift and rotate operations, start from the types defined in
> the Interfaces package, such as Interfaces.Unsigned_8 and other sizes.
>
> --
> Niklas Holsti
> Tidorum Ltd
> niklas holsti tidorum fi
> . @ .
>

Reply With Quote