Announcement

Collapse
No announcement yet.

Problems with bitshifting

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

  • Problems with bitshifting

    Hello to all,

    I tried in vain to in convert the functions below in C into working PB code...
    Can anybody help me ? Or is there now way to port this to PB ?

    1000+ thanks for any help.

    Oli


    static unsigned short base_dec(unsigned char *psrc)
    {
    unsigned short tmp;
    tmp= *psrc & 0x3f;
    tmp+=((unsigned short)(*(psrc+1) & 0x3f))<<6;
    tmp+=((unsigned short)(*(psrc+2) & 0x3f))<<12;
    return tmp;
    }

    static void base_enc(unsigned char *pdest, unsigned short value)
    {
    *pdest=(unsigned char)(value & 0x3f)+0x40;
    *(pdest+1)=((value >>6) & 0x3f)+0x40);
    *(pdest+2)=((value >>12) & 0x3f)+0x40);
    }

  • #2
    Oliver--

    Forum rules require that you use your full first and last names. Please re-register before posting additional messages. Thanks!

    Bob Zale
    PowerBASIC Inc.


    ------------------

    Comment


    • #3
      Oliver,

      I cant help w/ the C code, but here's a little tool that may help
      you figure it out:
      http://faqforums.com/BitMaskViewer.html

      Brad

      ------------------
      Wash DC Area

      Comment


      • #4
        Oliver,

        I think this might be it (not certain though):

        (use the STRPTR function to grab the pointer to the string)

        Code:
        DECLARE FUNCTION Base_Dec(psrc AS BYTE PTR) AS WORD
        
        
        SUB Base_Enc(pdest AS BYTE PTR, Value AS WORD)
        
        
            LOCAL tmp AS WORD
        
        
            'translation of: *pdest=(unsigned char)(value & 0x3f)+0x40;
            @pdest[0]=(value AND &H3F)+&H40
        
        
            'translation of: *(pdest+1)=((value >>6) & 0x3f)+0x40;
            tmp=value
            SHIFT RIGHT tmp,6
            @pdest[1]=(tmp AND &H3F)+&H40
        
        
            'translation of: *(pdest+2)=((value >>12) & 0x3f)+0x40;
            tmp=value
            SHIFT RIGHT tmp,12
            @pdest[2]=(tmp AND &H3F)+&H40
        
        
        END SUB
        
        
        FUNCTION Base_Dec(psrc AS BYTE PTR) AS WORD
        
        
            LOCAL tmp   AS WORD
            LOCAL tmp2  AS WORD
        
        
            'translation of: tmp= *psrc & 0x3f;
            [email protected][0] AND &H3F
        
        
            'translation of: tmp+=((unsigned short)(*(psrc+1) & 0x3f))<<6;
            [email protected][1] AND &H3F
            SHIFT LEFT tmp2,6
            tmp=tmp+tmp2
        
        
            'translation of: tmp+=((unsigned short)(*(psrc+2) & 0x3f))<<12;
            [email protected][2] AND &H3F
            SHIFT LEFT tmp2,12
            tmp=tmp+tmp2
        
        
            'translation of: return tmp;
            FUNCTION=tmp
        
        
        END FUNCTION


        ------------------
        Adam Drake
        Drake Software

        Comment

        Working...
        X