Announcement

Collapse
No announcement yet.

C conversion question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • C conversion question

    I converted the C code below, but I'm not sure if it's totally accurate. Can anyone see if I erred somewhere?

    C code
    Code:
    char * OutBits;
    int OutCount;
    char * InBits  ;
    
    /* Process input stream to yield output bits and two additional biased streams */
    void amls_round( int start, int end) 
    {
            if (start >= end ) return ;
            int doubles = start;
            int IndexLow  = start;
            int IndexHigh = end;
    
    
            do{
                    if (InBits[IndexLow] == InBits[IndexHigh]) 
                    {       
                            InBits[doubles++] = InBits[IndexLow];
                            InBits[IndexHigh] = '0'; 
                    }else{
                            OutBits[OutCount++] = InBits[IndexLow];
                            InBits[IndexHigh] = '1';
                    }       
                    IndexHigh--;
                    IndexLow++;
            }while (IndexHigh>IndexLow);
    /* Process the two derived streams */
    /* Remove both recursive calls to implement Von Neuman algorithm.*/
    /* Remove second recursive call to implement unadvanced MLS */
            amls_round(start,--doubles);  
            amls_round(++IndexHigh,end);
            return ;
    }

    My conversion

    Code:
    GLOBAL OutBits() AS BYTE
    GLOBAL OutCount AS LONG
    GLOBAL InBits() AS BYTE
    
    '/* Process input stream to yield output bits and two additional biased streams */
    FUNCTION amls_round(start AS LONG, finish AS LONG) AS LONG
    
            IF start >= finish THEN EXIT FUNCTION
    
            LOCAL doubles, IndexLow, IndexHigh AS LONG
            doubles = start
            IndexLow  = start
            IndexHigh = finish
    
    
            DO
                    IF InBits(IndexLow) = InBits(IndexHigh) THEN
    
                            InBits(doubles) = InBits(IndexLow)
                            INCR doubles
                            InBits(IndexHigh) = 48
                    ELSE
                            OutBits(OutCount) = InBits(IndexLow)
                            INCR OutCount
                            InBits(IndexHigh) = 49
                    END IF
                    DECR IndexHigh
                    INCR IndexLow
            LOOP WHILE IndexHigh > IndexLow
    
    '/* Process the two derived streams */
    '/* Remove both recursive calls to implement Von Neuman algorithm.*/
    '/* Remove second recursive call to implement unadvanced MLS */
            DECR doubles
            amls_round(start, doubles)
            INCR IndexHigh
            amls_round(IndexHigh, finish)
    END FUNCTION

  • #2
    looks OK except you need to DIM the global arrays.

    Comment


    • #3
      Thanks Chris, yes I do dim the arrays as GLOBAL BYTE in PBMAIN. It seems to run fine, but the output isn't exactly up to snuff. I'm thinking the C algo may be flawed some way, and just wanted to make sure it wasn't my translation.

      Comment


      • #4
        The only thing I noticed and probably doesn't make much difference is c function params a byval by default.
        Your Pb ones are byref by defalut

        James

        Comment


        • #5
          Thanks James, like you say it may not matter, but I'll test it BYVAL too.

          Comment

          Working...
          X