I'm looking at the C2B built-in function. When invoking it with ampersand or 
apostrophe, two ampersands or two apostrophes must be used as the argument. 
Here is a short test program that illustrates this.

TESTC2B  CSECT 
&C2B     SETC  C2B('&&')              error if only 1; returns 2
         MNOTE 'C2B(''&&&&'')=&C2B' 
         AIF   ('&C2B' NE '0101000001010000').C2ERR 
&C2B     SETC  C2B('''')              error if only 1; returns 1
         MNOTE 'C2B('''''''')=&C2B' 
         AIF   ('&C2B' NE '01111101').C2ERR 
         MNOTE 'All tests successful' 
         AGO   .EXIT 
.C2ERR   ANOP 
         MNOTE 12,'C2 OPERATOR ERROR' 
         AGO   .EXIT 
.EXIT    ANOP 
*
         END 

Assembling this with HLASM results in the "All tests successful" MNOTE. 
However, the returned C2B value for ampersand is the binary value for two 
ampersands. This surprised me. The returned C2B value for apostrophe is the 
binary value for one apostrophe, as expected. Can anyone explain why the 
ampersand value is different?

Snippet from HLASM output.

 1 TESTC2B  CSECT                                                  
 2 &C2B     SETC  C2B('&&')              error if only 1; returns 2
 3          MNOTE 'C2B(''&&&&'')=&C2B'                             
  +C2B('&&')=0101000001010000                                      
 4          AIF   ('&C2B' NE '0101000001010000').C2ERR             
 5 &C2B     SETC  C2B('''')              error if only 1; returns 1
 6          MNOTE 'C2B('''''''')=&C2B'                             
  +C2B('''')=01111101                                              
 7          AIF   ('&C2B' NE '01111101').C2ERR                     
 8 All tests successful                                            
 9          AGO   .EXIT                                            
10 .EXIT    ANOP                                                   
11 *                                                               
12          END                                                    

Regards, John Ganci

Reply via email to