Skip to main content

[Migrated content. Thread originally posted on 08 March 2005]

Anyone know how I can do bit shifts left and right in aucobol? For instance where binary 0101 when shifted 1 bit left becomes 1010. I don't need a circular shift.

The shift may also be for x number of bits, not necessarily for all bits.

[Migrated content. Thread originally posted on 08 March 2005]

Anyone know how I can do bit shifts left and right in aucobol? For instance where binary 0101 when shifted 1 bit left becomes 1010. I don't need a circular shift.

The shift may also be for x number of bits, not necessarily for all bits.
solution 1: use a C compiler

move numeric data to a binary type (comp-5, comp-x, unsigned-int)
create small dll accepting dword * parameter for value, dword * for shift. you can return the value as return code. This is easy but may have long term portability issues. rigging up 64 bit is of course also possible (and a little bit more work) usage pointer is a 64 bit binary type.

solution 2: the cobol way
may one small program with the linkage pretty much the same as above (plus the shift mode)

shift left:
evaluate shift
when 0 continue
when 1 multiply value by 2
when 2 multiply value by 4
[...]

since you don'y require wraparound this isn't too much work :)

Merlin

[Migrated content. Thread originally posted on 08 March 2005]

Anyone know how I can do bit shifts left and right in aucobol? For instance where binary 0101 when shifted 1 bit left becomes 1010. I don't need a circular shift.

The shift may also be for x number of bits, not necessarily for all bits.
Originally posted by MerlinM

solution 2: the cobol way
may one small program with the linkage pretty much the same as above (plus the shift mode)

shift left:
evaluate shift
when 0 continue
when 1 multiply value by 2
when 2 multiply value by 4
[...]

since you don'y require wraparound this isn't too much work :)

Merlin



Thanks, Merlin, turns out I don't need the shifting right now.

[Migrated content. Thread originally posted on 08 March 2005]

Anyone know how I can do bit shifts left and right in aucobol? For instance where binary 0101 when shifted 1 bit left becomes 1010. I don't need a circular shift.

The shift may also be for x number of bits, not necessarily for all bits.
Originally posted by MerlinM

solution 2: the cobol way
may one small program with the linkage pretty much the same as above (plus the shift mode)

shift left:
evaluate shift
when 0 continue
when 1 multiply value by 2
when 2 multiply value by 4
[...]

since you don'y require wraparound this isn't too much work :)

Merlin



Thanks, Merlin, turns out I don't need the shifting right now.