Téma:   Hexadecimální a binární zobrazení textových řádků dat - vstupem je Stdin nebo klávesnice

ČeV-OC  ~ ~ ~  JDoodle Online COBOL Compiler IDE ... ~ ~ ~ a70.txt

program-id.                                                              
    a70-interni-zobrazeni-dat.                                                              
        *> vstupem jsou řádky Stdin nebo interaktivně vložené z klávesnice, ukončené "Enter", 
        *> výstupem je hexadecimální zobrazení vstupu, při CMD-Line = "b" je k tomu i binární,
        *> limit pro trvání interaktivní práce je asi 1 minuta 
                                                                         
data division.
    working-storage section.                                                 
        1  BAJT pic x.                                                          
        1  BITY.                                                                
            2  LB.                                                                 
                3  L1 pic 99 comp-x.                                                  
                3  L2 pic 99 comp-x.                                                  
                3  L3 pic 99 comp-x.                                                  
                3  L4 pic 99 comp-x.                                                  
            2  PB.                                                                 
                3  P1 pic 99 comp-x.                                                  
                3  P2 pic 99 comp-x.                                                  
                3  P3 pic 99 comp-x.                                                  
                3  P4 pic 99 comp-x.                                                  
        1  KODY.                                                                
            2  LB.                                                                 
                3  L1 pic 9.                                                          
                3  L2 pic 9.                                                          
                3  L3 pic 9.                                                          
                3  L4 pic 9.                                                          
            2  PB.                                                                 
                3  P1 pic 9.                                                          
                3  P2 pic 9.                                                          
                3  P3 pic 9.                                                          
                3  P4 pic 9.                                                          
        1  T pic 9999.                                                          
        1  TV pic x.                                                            
        1  V.                                                                   
            2  V1 pic x.                                                           
            2  V2 pic x.                                                           
        77 RADEK-C pic x(80).
        77 RADEK-S pic x(80).
            88 PRACE value "*".
            88 KONEC value " ".
        77 D pic 999.
        77 I pic 999.
        77 H pic 999.
        77 B pic 999.
        77 RADEK-H pic x(160).
        77 RADEK-B pic x(160).

procedure division.
    perform PRECTI-C
    perform PRECTI-S
    stop run.
    
PRECTI-C.
    accept RADEK-C from command-line
    display "----- C = " RADEK-C
    .
PRECTI-S.
    set PRACE to true
    perform until KONEC
        accept RADEK-S 
        if not KONEC
            perform HEXA
        end-if end-perform
    display "----- KONEC"
    .
HEXA.
    display "     ....*....1....*....2....*....3....*....4....*....5....*....6....*....7"
    move 0 to D
    inspect RADEK-S tallying D for trailing " "
    compute D = 80 - D
    display D "  " RADEK-S 
    move space to RADEK-H RADEK-B
    move 1 to H B
    
    perform varying I from 1 by 1 until I > D
        move RADEK-S(I:1) to BAJT 
        call x"F5" using BAJT BITY
        move corr BITY to KODY                                           
        move LB of KODY to T perform TST move TV to V1
        move PB of KODY to T perform TST move TV to V2                      
        move V to RADEK-H(H:2)
        add 3 to H
        if RADEK-C = "b"
            string LB of KODY " " PB of KODY delimited size 
            into RADEK-B(B:9)
            add 10 to B
        end-if end-perform
        
    compute D = 2 * D
    display D "  " RADEK-H
    if RADEK-C = "b"
        compute D = 4 * D
        display D "  " RADEK-B
        end-if
    .
TST.                                                                     
    evaluate T                                                           
       when 0000   move "0" to TV                                        
       when 0001   move "1" to TV                                        
       when 0010   move "2" to TV                                        
       when 0011   move "3" to TV                                        
       when 0100   move "4" to TV                                        
       when 0101   move "5" to TV                                        
       when 0110   move "6" to TV                                        
       when 0111   move "7" to TV                                        
       when 1000   move "8" to TV                                        
       when 1001   move "9" to TV                                        
       when 1010   move "a" to TV                                        
       when 1011   move "b" to TV                                        
       when 1100   move "c" to TV                                        
       when 1101   move "d" to TV                                        
       when 1110   move "e" to TV                                        
       when 1111   move "f" to TV                                        
    end-evaluate.  
                                                      
 

ČeV - 28.5.2020