Bitwise shift operator?

Hello all,

Currently, I am building a CRC-16 calculator by app inventor 2.
I need bitwise shift operator which like, “>>” , “<<” , in my program,
but I am a newcomer of Inventor 2.

I can not find the block for it. Does anyone know where can I find that, or any suggestion.

Best Regards,
Fan

can you show your block for we help you

Sure, Please have it.
Currently, it is not completed function.
You should see that I am currently using division by 256 to replace the right shift operator for 8 bit.


However, after testing, it’s wrong

I also provide my C code algorithm for you reference.
The blocks is followed this algorithm to establish.


crc.aia (5.2 KB)

I have created an procedure for bitwise shift operator.
For everyone reference.

Sorry, maybe I don’t understand what you mean, and this app you make it for what.
Thank you

I love bit manipulation.

If you break up the shift function to separate Left and Right variants, you can drop the text 'right' or 'left' parameter and test, and let AI2 typeblocking help you specify the direction.
shiftRight shiftLeft


shift_test

Procedure and test blocks are draggable into Blocks Editor,
screen shot not draggable.

(edit-ABG)
P.S. This shift left operator is wrong, in that it does not take into account the 16 bit unsigned data type being shifted left.
There are two schools of thought as to what results from a shift left that overflows the left end:

  • The result is undefined, or
  • You clip the overflow.

This question can be only answered by examining the original algorithm source and its environment.

2 Likes

Please make me understain @ABG :sob: i want to learn something

1 Like

Regarding your CRC function, is it working for you?

I notice you treat parameter buf as a list, yet receive a len parameter that you treat like the length of the buf list.

There is a length of list function list block that you could use (length of list(buf)) to eliminate that len parameter.

Another example of shift register

p91A_registro_desplaza.aia (2.4 KB)

Hi ABG,

Thanks your kindly suggestion.
It’s useful for me.

I occasionally understain.
It Depends.

If you want to understand CRC (Cyclic Redundancy Check) try
https://www.google.com/search?q=Cyclic+Redundancy+Check