SHIFT,OR and AND operators in modula-2

Dear experts,

I use Native XDS-x86 modula-2 compiler.

I need to use the bitwise left and right shift and witwise OR and AND operations on cardinal values.

what are the operators and and definitions modules.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I am not a modula programmer but in checking the Modula language I don't find that it has those operators.     Since the Native compiler allows the use of C code could you be looking for the C operators.

mlmoc is qute right, the operators are not there in the vasic language.

Instead modula have the idea of sets, and you can get the bitwise logic done using sets:

var bitNumber1, bitNumber2, resultat :
                            CASE t : BOOLEAN OF
                                TRUE:   nr: INTEGER
                                 FALSE: bs: SET OF [0..30];   (* assuming INTEGER is 32 bit signed *)

bitNumber1.t := TRUE; := 121;                 (* 00000000 00000000 00000000 01111001 *)
bitNumber2.t := TRUE; := 195;                 (* 00000000 00000000 00000000 11000011 *)

bitNumber1.t := FALSE;
bitNumber1.t := FALSE;
resultat.t := FALSE; := +             (* set union == bitwise or *)
resultat.t := TRUE;
writeln( "OR gives " );   (* 00000000 00000000 00000000 11111011 (251) *)

resultat.t := FALSE; := *             (* set intersection ==  bitwise and *)
resultat.t := TRUE;
writeln( "AND gives " ); (* 00000000 00000000 00000000 01000001 (65) *)

for the shifting you multiply or divide by some power of 2

bitNumber1.t := TRUE; := * (2*2*2);                 (* shift up 3 bitpositions *)
                                                     (* 00000000 00000000 00000011 11001000 *) := / (2*2*2);                 (* shift down 3 bitpositions (NB signed shift)*)
                                                     (* 00000000 00000000 00000000 00001111 *)

It is clumsy but it works.  Still I would recommend you rewiew your prigramming task considering sets. there may be a much prettier solution.

regards JakobA

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
slathakamatchiAuthor Commented:
Hi Jacob,

Let me try this and let you know soon.

Thank you
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.