Menu

Bit shift problem

Help
MBB
2 days ago
1 day ago
  • MBB

    MBB - 2 days ago

    I'm using:
    GCASM List File (GCBASIC 0.99.01 2022-01-27 (Windows 64 bit) : Build 1073)
    with an 18F4550.

    I wrote this simple code:

    dim coef_0 as word
    
    coef_0 = FnLSL(17, 4)
    
    print coef_0
    

    When I run the code it says coef_0 = 17.

    I think it should be 272.

    What am I doing wrong?

     
  • MBB

    MBB - 2 days ago

    Correction

    When I run the code it says coef_0 = 16 not 17

     
  • Anobium

    Anobium - 2 days ago

    Time to update the compiler... going for the oldest compiler in use award. :-) SMILING

    Compiled with GCBASIC (2025.11.12 (Windows 64 bit) : Build 1527) using PIC-AS ( not GCASM).

    dim coef_0 as word
    coef_0 = FnLSL([WORD]17, 4)
    print coef_0
    

    Gives 272.

    Note: You have to case the input variable. The compiler does not really know what the constant 17 is to be treated as. So, the cast tells the compiler to treat as a word.

     
  • MBB

    MBB - 2 days ago

    Thanks!

    That worked

     
    • Anobium

      Anobium - 2 days ago

      Did the explaination make sense?

      The ASM shows the process. In the next release you can walk the program in a real Debugger to see what is happening.

       
  • MBB

    MBB - 1 day ago

    yes, it made sense.

     

Log in to post a comment.