Skip to content

Viper bit manipulation challenges #15987

Discussion options

You must be logged in to vote

See here for a detailed description of Viper: https://github.com/micropython/micropython/wiki/Improving-performance-with-Viper-code

In both examples, you pass d[0] to bit_manip. You need to call bit_manip(d), so that within bit_manip, A becomes a pointer to the array d, and A[0] is the first element of d.

((A[0] >> 1 & 1) != 0) yields a boolean because of the != operator. B:int is then overridden and B winds up as a boolean. That's why you need to cast with int() again. Note that B:int is not a type cast, it's only a type hint. In fact, in viper functions, the only type hints that do something are the type hints of parameters and of the return type. B:int = something does not influence wh…

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@sk8board
Comment options

@bixb922
Comment options

Answer selected by sk8board
Comment options

You must be logged in to vote
1 reply
@bixb922
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants