SUBROUTINE ASC4(INBYTE,OUTBYTE) C This subroutine takes an array of 3 bytes (24 bits) and converts C it to an array of 4 bytes by taking the 24-bit string and C cutting it into 4 6-bit strings. Each 6-bit string is C right-justified in one of the output bytes and the value 40(8) C is added to it to insure that the value will represent a C printable ASCII character in the range 040(8) to 137(8). C (blank to underbar) C C All bit manipulation is done in INTEGER variables since C DEC FORTRAN does not allow bitwise logical operations on C BYTE data. C C Input data Output data C C bbaaaaaa byte 1 00aaaaaa + 00100000 byte 1 C ccccbbbb byte 2 00bbbbbb + 00100000 byte 2 C ddddddcc byte 3 00cccccc + 00100000 byte 3 C 00dddddd + 00100000 byte 4 C C aaaaaa is the first 6-bit string, bbbbbb is the second, etc. C BYTE INBYTE(3) !Input byte array BYTE OUTBYTE(4) !Output byte array INTEGER TEMP1,TEMP2 !Work space for bit manipulations DATA MASK2,MASK4,MASK6,MASK8 !MASKn is an AND mask used to eliminate 1 /"3,"17,"77,"377 / !all but the lowest n bits of a word. C C Compute 1st output byte. C TEMP1=INBYTE(1) !Get byte with 1st bit string. TEMP1=TEMP1 .AND. MASK6 !Erase all but 1st bit string. TEMP1=TEMP1+"040 !Make it printable. OUTBYTE(1)=TEMP1 !Copy to output byte 1 C C Compute 2nd output byte C TEMP1=INBYTE(1) !Get byte with part of 2nd bit string. TEMP1=TEMP1 .AND. MASK8 !Clear garbage out of top half of word. TEMP1=ISHFT(TEMP1,-6) !Shift our 2 bits to right end of byte. TEMP2=INBYTE(2) !Get byte with rest of 2nd bit string. TEMP2=TEMP2 .AND. MASK4 !Keep the top 4 bits of 2nd bit string. TEMP2=ISHFT(TEMP2,2) !Shift them left to the right position. TEMP1=TEMP1 .OR. TEMP2 !Merge the two pieces. TEMP1=TEMP1+"040 !Make the result printable. OUTBYTE(2)=TEMP1 !Copy to 2nd output byte. C C Compute 3rd output byte C TEMP1=INBYTE(2) !Get byte with half of 3rd bit string. TEMP1=TEMP1 .AND. MASK8 !Clear garbage out of top half of word. TEMP1=ISHFT(TEMP1,-4) !Shift our 4 bits to right end of byte. TEMP2=INBYTE(3) !Get byte with rest of 3rd bit string. TEMP2=TEMP2 .AND. MASK2 !Keep the top 2 bits of 3rd bit string. TEMP2=ISHFT(TEMP2,4) !Shift them left to the right position. TEMP1=TEMP1 .OR. TEMP2 !Merge the two pieces. TEMP1=TEMP1+"040 !Make the result printable OUTBYTE(3)=TEMP1 !Copy to 3rd output byte. C C Compute 4th output byte C TEMP1=INBYTE(3) !Get byte with 4th bit string. TEMP1=TEMP1 .AND. MASK8 !Clear garbage out of top half of word. TEMP1=ISHFT(TEMP1,-2) !Shift our 6 bits to right end of byte. TEMP1=TEMP1+"040 !Make the result printable. OUTBYTE(4)=TEMP1 !Copy to 4th output byte. C RETURN END