damn simple bug... help lads

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


hi guys, I hav this piece of code:

the output is:

 

value 6

value 4

 

instead of 4 it should be 64.  Any suggestions?

 

This topic has a solution.
Last Edited: Tue. Apr 30, 2019 - 08:28 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try  2 << mbr->...    , instead of 2 ^

 

 

Edit: but it seems to be either  1<< mbr...   or 2 << ((mbr...) -1)  .. to get 64 

 

Edit2: ^ is the XOR operator in C  , exponent is pow(x,y)  - https://www.microchip.com/webdoc...

 

/Bingo

Last Edited: Tue. Apr 30, 2019 - 08:19 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

^ is the bitwise XOR operator, not an exponentiation operator. There are exponentiation functions for floats/doubles in the math header.

github.com/apcountryman/build-avr-gcc: a script for building avr-gcc

github.com/apcountryman/toolchain-avr-gcc: a CMake toolchain for cross compiling for the Atmel AVR family of microcontrollers

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm a fing eejit.