Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shifting number

Status
Not open for further replies.

Honza

Programmer
Jun 28, 2000
1
CZ
Hello!<br><br>&nbsp;&nbsp;&nbsp;&nbsp;please, I'd like to know how to shift number left or right (similary to C++&nbsp;&nbsp;&gt;&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;or Pascal shl,shr). <br>I'm looking for something better than dividing and multiplying by 2.<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Thanks&nbsp;&nbsp;Honza Klimes&nbsp;&nbsp;<br>(<A HREF="mailto:j_klimes@ortex.cz">j_klimes@ortex.cz</A>)
 
Honza,<br><br>Are you trying to shift binary or decimal number (or other...)?<br>Tip for decimal shifting left:<br><br>WORKING-STORAGE SECTION.<br>01 NUMB1 PIC 9(10).<br>01 NUMB11 REDEFINES NUMB1.<br>&nbsp;&nbsp;&nbsp;&nbsp;03 N11 PIC 9 OCCURS 10.<br>01 NUMB2 PIC 9(10).<br>01 NUMB21 REDEFINES NUMB2.<br>&nbsp;&nbsp;&nbsp;&nbsp;03 N21 PIC 9 OCCURS 10.<br>01 VARIAB.<br>&nbsp;&nbsp;&nbsp;&nbsp;03 K PIC 99.<br>&nbsp;&nbsp;&nbsp;&nbsp;03 J PIC 99.<br><br>...<br><br>PROCEDURE DIVISION.<br><br>&nbsp;ACCEPT NUMB1 WITH CONVERSION.<br>&nbsp;PERFORM SHIFTT VARYING K FROM 1 BY 1 UNTIL K &gt; 10.<br><br>&nbsp;DISPLAY NUMB2 WITH CONVERSION.<br><br>&nbsp;STOP RUN.<br><br>SHIFTT.<br>&nbsp;COMPUTE J = K + 1.<br>&nbsp;IF J &lt; 11<br>&nbsp;&nbsp;MOVE N11(K) TO N21(J)<br>* if you want cyclic shift you should put last (11) digit in the first place.<br>* ELSE MOVE N11(K) TO N21(1).<br>&nbsp;&nbsp;ELSE ZERO TO N21(1).<br><br><br>
 
There are hundreds of ways to do this. <br>For example:<br><br>01 original pic 9(18).<br>01 right-shift redefines original pic 9(17)v9.<br>01 original-string redefines original pic x(18).<br>....<br><br>move original to right-shift.<br><br>that creates a numeric move.<br><br>original-string = original-string(2:)<br><br>creates a leftshift, the last byte becomes blanc!<br><br>but there are endless ways to do things like this.<br>experiment with them and have fun.<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top