RosettaCodeData/Task/Bitwise-operations/PL-I/bitwise-operations.pli

26 lines
868 B
Plaintext

/* PL/I can perform bit operations on binary integers. */
k = iand(i,j);
k = ior(i,j);
k = inot(i,j);
k = ieor(i,j);
k = isll(i,n); /* unsigned shifts i left by n places. */
k = isrl(i,n); /* unsigned shifts i right by n places. */
k = lower2(i, n); /* arithmetic right shift i by n places. */
k = raise2(i, n); /* arithmetic left shift i by n places. */
/* PL/I can also perform boolean operations on bit strings */
/* of any length: */
declare (s, t, u) bit (*);
u = s & t; /* logical and */
u = s | t; /* logical or */
u = ^ s; /* logical not */
u = s ^ t; /* exclusive or */
Built-in rotate functions are not available.
They can be readily implemented by the user, though:
u = substr(s, length(s), 1) || substr(s, 1, length(s)-1); /* implements rotate right. */
u = substr(s, 2) || substr(s, 1, 1); /* implements rotate left. */