user25751: I have an Arduino Nano and was adding up some values 2^i from 0..7:
void setup() {
  Serial.begin(9600);
  int i,k;
  k = 0;
  for (i=0;i<8;i++){
     k += pow(2, i);
     Serial.println(k);
  }
}

Those numbers should sum up to 255, but that's the output:
1
3
6
13
28
59
122
249

Is my Arduino not working or what can be the reason for this behaviour?

user4143: No, there is nothing "wrong" there. In fact it's the expected results.
The problem here is that pow() returns a float, and some numbers just can't be represented with floating point. When that floating point value is converted to an integer it truncates the decimal portion leaving you with the wrong integer value.
void setup() {
    Serial.begin(115200);

    int t = 0;
    for (int i = 0; i < 8; i++) {
        float f = pow(2, i);
        int d = f;
        t += f;
        Serial.print("2^");
        Serial.print(i);
        Serial.print(": float = ");
        Serial.print(f, 10);
        Serial.print(" int = ");
        Serial.print(d);
        Serial.print(" total = ");
        Serial.println(t);
    }
}

void loop() {
}

2^0: float = 1.0000000000 int = 1 total = 1
2^1: float = 2.0000000000 int = 2 total = 3
2^2: float = 3.9999995231 int = 3 total = 6
2^3: float = 7.9999980926 int = 7 total = 13
2^4: float = 15.9999961853 int = 15 total = 28
2^5: float = 31.9999885559 int = 31 total = 59
2^6: float = 63.9999771118 int = 63 total = 122
2^7: float = 127.9999542236 int = 127 total = 249

Instead you should use bit-shifting to perform the same operation on an integer:
void setup() {
    Serial.begin(115200);

    int t = 0;
    for (int i = 0; i < 8; i++) {
        int d = 1 << i;
        t += d;
        Serial.print("1<<");
        Serial.print(i);
        Serial.print(": int = ");
        Serial.print(d);
        Serial.print(" total = ");
        Serial.println(t);
    }
}

void loop() {
}

1<<0: int = 1 total = 1
1<<1: int = 2 total = 3
1<<2: int = 4 total = 7
1<<3: int = 8 total = 15
1<<4: int = 16 total = 31
1<<5: int = 32 total = 63
1<<6: int = 64 total = 127
1<<7: int = 128 total = 255


25751: <p>I have an Arduino Nano and was adding up some values <code>2^i from 0..7</code>:</p>

<pre><code>void setup() {
  Serial.begin(9600);
  int i,k;
  k = 0;
  for (i=0;i&lt;8;i++){
     k += pow(2, i);
     Serial.println(k);
  }
}
</code></pre>

<p>Those numbers should sum up to <code>255</code>, but that's the output:</p>

<pre><code>1
3
6
13
28
59
122
249
</code></pre>

<p>Is my Arduino not working or what can be the reason for this behaviour?</p>
 4143: <p>No, there is nothing "wrong" there. In fact it's the expected results.</p>

<p>The problem here is that <code>pow()</code> returns a float, and some numbers just can't be represented with floating point. When that floating point value is converted to an integer it truncates the decimal portion leaving you with the wrong integer value.</p>

<pre><code>void setup() {
    Serial.begin(115200);

    int t = 0;
    for (int i = 0; i &lt; 8; i++) {
        float f = pow(2, i);
        int d = f;
        t += f;
        Serial.print("2^");
        Serial.print(i);
        Serial.print(": float = ");
        Serial.print(f, 10);
        Serial.print(" int = ");
        Serial.print(d);
        Serial.print(" total = ");
        Serial.println(t);
    }
}

void loop() {
}

2^0: float = 1.0000000000 int = 1 total = 1
2^1: float = 2.0000000000 int = 2 total = 3
2^2: float = 3.9999995231 int = 3 total = 6
2^3: float = 7.9999980926 int = 7 total = 13
2^4: float = 15.9999961853 int = 15 total = 28
2^5: float = 31.9999885559 int = 31 total = 59
2^6: float = 63.9999771118 int = 63 total = 122
2^7: float = 127.9999542236 int = 127 total = 249
</code></pre>

<p>Instead you should use bit-shifting to perform the same operation on an integer:</p>

<pre><code>void setup() {
    Serial.begin(115200);

    int t = 0;
    for (int i = 0; i &lt; 8; i++) {
        int d = 1 &lt;&lt; i;
        t += d;
        Serial.print("1&lt;&lt;");
        Serial.print(i);
        Serial.print(": int = ");
        Serial.print(d);
        Serial.print(" total = ");
        Serial.println(t);
    }
}

void loop() {
}

1&lt;&lt;0: int = 1 total = 1
1&lt;&lt;1: int = 2 total = 3
1&lt;&lt;2: int = 4 total = 7
1&lt;&lt;3: int = 8 total = 15
1&lt;&lt;4: int = 16 total = 31
1&lt;&lt;5: int = 32 total = 63
1&lt;&lt;6: int = 64 total = 127
1&lt;&lt;7: int = 128 total = 255
</code></pre>
