user76080: I have an array of hexadecimal values as given below.
byte Hexa_Val[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

I want to increase this array from the end. As in, go from {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} all the way to {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF}, and then increase the value next to it to {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00}, and continue. The increment should go as shown below.
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}
.
.
.
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF}
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00}
.
.
.
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF}
{0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00}
.
.
.
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}

The code I am came up with is
byte Hexa_Val[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 

void setup() {
  Serial.begin(115200);
}

void loop() {

  Hexa_Val[7] = Hexa_Val[7] + 1;

  if(Hexa_Val[7] = 0xFF){
    Hexa_Val[6] = Hexa_Val[6] + 1;
    Hexa_Val[7] = 0x00;    
  }

  if((Hexa_Val[7] = 0xFF) && (Hexa_Val[6] = 0xFF)){
    Hexa_Val[5] = Hexa_Val[5] + 1;
    Hexa_Val[7] = 0x00;
    Hexa_Val[6] = 0x00;      
  }

  if((Hexa_Val[7] = 0xFF) && (Hexa_Val[6] = 0xFF) && (Hexa_Val[5] = 0xFF)){
    Hexa_Val[4] = Hexa_Val[4] + 1;
    Hexa_Val[7] = 0x00;
    Hexa_Val[6] = 0x00;
    Hexa_Val[5] = 0x00;       
  }

  if((Hexa_Val[7] = 0xFF) && (Hexa_Val[6] = 0xFF) && (Hexa_Val[5] = 0xFF) && (Hexa_Val[4] = 0xFF)){
    Hexa_Val[3] = Hexa_Val[3] + 1;
    Hexa_Val[7] = 0x00;
    Hexa_Val[6] = 0x00;
    Hexa_Val[5] = 0x00;
    Hexa_Val[4] = 0x00;        
  }

  if((Hexa_Val[7] = 0xFF) && (Hexa_Val[6] = 0xFF) && (Hexa_Val[5] = 0xFF) && (Hexa_Val[4] = 0xFF) && (Hexa_Val[3] = 0xFF)){
    Hexa_Val[2] = Hexa_Val[2] + 1;
    Hexa_Val[7] = 0x00;
    Hexa_Val[6] = 0x00;
    Hexa_Val[5] = 0x00;
    Hexa_Val[4] = 0x00;
    Hexa_Val[3] = 0x00;         
  }

  if((Hexa_Val[7] = 0xFF) && (Hexa_Val[6] = 0xFF) && (Hexa_Val[5] = 0xFF) && (Hexa_Val[4] = 0xFF) && (Hexa_Val[3] = 0xFF) && (Hexa_Val[2] = 0xFF)){
    Hexa_Val[1] = Hexa_Val[1] + 1;
    Hexa_Val[7] = 0x00;
    Hexa_Val[6] = 0x00;
    Hexa_Val[5] = 0x00;
    Hexa_Val[4] = 0x00;
    Hexa_Val[3] = 0x00;
    Hexa_Val[2] = 0x00;         
  }

  if((Hexa_Val[7] = 0xFF) && (Hexa_Val[6] = 0xFF) && (Hexa_Val[5] = 0xFF) && (Hexa_Val[4] = 0xFF) && (Hexa_Val[3] = 0xFF) && (Hexa_Val[2] = 0xFF)  && (Hexa_Val[1] = 0xFF)){
    Hexa_Val[0] = Hexa_Val[0] + 1;
    Hexa_Val[7] = 0x00;
    Hexa_Val[6] = 0x00;
    Hexa_Val[5] = 0x00;
    Hexa_Val[4] = 0x00;
    Hexa_Val[3] = 0x00;
    Hexa_Val[2] = 0x00;
    Hexa_Val[1] = 0x00;           
  }

  if((Hexa_Val[7] = 0xFF) && (Hexa_Val[6] = 0xFF) && (Hexa_Val[5] = 0xFF) && (Hexa_Val[4] = 0xFF) && (Hexa_Val[3] = 0xFF) && (Hexa_Val[2] = 0xFF) && (Hexa_Val[1] = 0xFF)  && (Hexa_Val[0] = 0xFF)){
    Hexa_Val[7] = 0x00;
    Hexa_Val[6] = 0x00;
    Hexa_Val[5] = 0x00;
    Hexa_Val[4] = 0x00;
    Hexa_Val[3] = 0x00;
    Hexa_Val[2] = 0x00;
    Hexa_Val[1] = 0x00;
    Hexa_Val[0] = 0x00;           
  }

  //to find out what I am sending 
  for( byte a=0; a<8; a++ ) {
    Serial.print(Hexa_Val[a], HEX);
  }
  Serial.println(); 

  delay(500);

}

But it just gives me zeros in the serial monitor. If I just leave the first two IF statements
byte Hexa_Val[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 

void setup() {
  Serial.begin(115200);
}

void loop() {

  Hexa_Val[7] = Hexa_Val[7] + 1;

  if(Hexa_Val[7] = 0xFF){
    Hexa_Val[6] = Hexa_Val[6] + 1;
    Hexa_Val[7] = 0x00;    
  }

  if((Hexa_Val[7] = 0xFF) && (Hexa_Val[6] = 0xFF)){
    Hexa_Val[5] = Hexa_Val[5] + 1;
    Hexa_Val[7] = 0x00;
    Hexa_Val[6] = 0x00;      
  }

  //to find out what I am sending 
  for( byte a=0; a<8; a++ ) {
    Serial.print(Hexa_Val[a], HEX);
  }
  Serial.println(); 

  delay(500);

}

The increment will start from the third value on the right. Something like
00000200
00000300
00000400
00000500
00000600
00000700

How do I get it to increase as I mentioned at the beginning? Why does the code recognize 0xFF as a zero?

user7508: There are multiple problems here:

if(Hexa_Val[7] = 0xFF)

First of all, = is the assignment operator. You are setting
Hexa_Val[7] to 0xFF. If you want to compare for equality, you should
use ==.
Second problem, The value 0xff will never be displayed, because you
are replacing it by zero. This byte will then count 0xfd, 0xfe, 0x00,
skipping 0xff. If you want to count 0xff, the condition should be
Hexa_Val[7] == 0, i.e. increment Hexa_Val[6] only after
Hexa_Val[7] has overflowed.
Third problem, your second if test comes too late. At this point
Hexa_Val[7] has already been reset. You should test for Hexa_Val[6]
overflowing only within the previous test.
With all that fixed:
Hexa_Val[7] = Hexa_Val[7] + 1;
if (Hexa_Val[7] == 0) {
  Hexa_Val[6] = Hexa_Val[6] + 1;
  if (Hexa_Val[6] == 0) {
    Hexa_Val[5] = Hexa_Val[5] + 1;
  }
}

If you don't want to write 8 nested conditions (which is kind of
cumbersome), you can instead loop over the array backwards, incrementing
each element in turn, and break out of the loop as soon as an increment
does not overflow:
for (int i = 7; i >= 0; i--) {
    if (++Hexa_Val[i] != 0) break;
}

If you don't mind the array being backwards, you can also handle the
whole array as a single 64-bit number, and just increment it like you
would increment any integer. But then you have to print the array
backwards, starting from the mast element:
union {
    uint64_t number;
    byte bytes[8];
} Hexa_Val = { .number = 0 };

void loop() {
    // Increment the array.
    Hexa_Val.number++;

    // Print out.
    for (int i = 7; i >= 0; i--) {
        if (Hexa_Val.bytes[i] < 0x10) Serial.write('0');
        Serial.print(Hexa_Val.bytes[i], HEX);
        Serial.write(' ');
    }
    Serial.println(); 

    delay(500);
}


76080: <p>I have an array of hexadecimal values as given below.</p>
<pre><code>byte Hexa_Val[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
</code></pre>
<p>I want to increase this array from the end. As in, go from {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} all the way to {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF}, and then increase the value next to it to {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00}, and continue. The increment should go as shown below.</p>
<pre><code>{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02}
.
.
.
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF}
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00}
.
.
.
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF}
{0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00}
.
.
.
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
</code></pre>
<p>The code I am came up with is</p>
<pre><code>byte Hexa_Val[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 

void setup() {
  Serial.begin(115200);
}

void loop() {

  Hexa_Val[7] = Hexa_Val[7] + 1;

  if(Hexa_Val[7] = 0xFF){
    Hexa_Val[6] = Hexa_Val[6] + 1;
    Hexa_Val[7] = 0x00;    
  }

  if((Hexa_Val[7] = 0xFF) &amp;&amp; (Hexa_Val[6] = 0xFF)){
    Hexa_Val[5] = Hexa_Val[5] + 1;
    Hexa_Val[7] = 0x00;
    Hexa_Val[6] = 0x00;      
  }

  if((Hexa_Val[7] = 0xFF) &amp;&amp; (Hexa_Val[6] = 0xFF) &amp;&amp; (Hexa_Val[5] = 0xFF)){
    Hexa_Val[4] = Hexa_Val[4] + 1;
    Hexa_Val[7] = 0x00;
    Hexa_Val[6] = 0x00;
    Hexa_Val[5] = 0x00;       
  }

  if((Hexa_Val[7] = 0xFF) &amp;&amp; (Hexa_Val[6] = 0xFF) &amp;&amp; (Hexa_Val[5] = 0xFF) &amp;&amp; (Hexa_Val[4] = 0xFF)){
    Hexa_Val[3] = Hexa_Val[3] + 1;
    Hexa_Val[7] = 0x00;
    Hexa_Val[6] = 0x00;
    Hexa_Val[5] = 0x00;
    Hexa_Val[4] = 0x00;        
  }

  if((Hexa_Val[7] = 0xFF) &amp;&amp; (Hexa_Val[6] = 0xFF) &amp;&amp; (Hexa_Val[5] = 0xFF) &amp;&amp; (Hexa_Val[4] = 0xFF) &amp;&amp; (Hexa_Val[3] = 0xFF)){
    Hexa_Val[2] = Hexa_Val[2] + 1;
    Hexa_Val[7] = 0x00;
    Hexa_Val[6] = 0x00;
    Hexa_Val[5] = 0x00;
    Hexa_Val[4] = 0x00;
    Hexa_Val[3] = 0x00;         
  }

  if((Hexa_Val[7] = 0xFF) &amp;&amp; (Hexa_Val[6] = 0xFF) &amp;&amp; (Hexa_Val[5] = 0xFF) &amp;&amp; (Hexa_Val[4] = 0xFF) &amp;&amp; (Hexa_Val[3] = 0xFF) &amp;&amp; (Hexa_Val[2] = 0xFF)){
    Hexa_Val[1] = Hexa_Val[1] + 1;
    Hexa_Val[7] = 0x00;
    Hexa_Val[6] = 0x00;
    Hexa_Val[5] = 0x00;
    Hexa_Val[4] = 0x00;
    Hexa_Val[3] = 0x00;
    Hexa_Val[2] = 0x00;         
  }

  if((Hexa_Val[7] = 0xFF) &amp;&amp; (Hexa_Val[6] = 0xFF) &amp;&amp; (Hexa_Val[5] = 0xFF) &amp;&amp; (Hexa_Val[4] = 0xFF) &amp;&amp; (Hexa_Val[3] = 0xFF) &amp;&amp; (Hexa_Val[2] = 0xFF)  &amp;&amp; (Hexa_Val[1] = 0xFF)){
    Hexa_Val[0] = Hexa_Val[0] + 1;
    Hexa_Val[7] = 0x00;
    Hexa_Val[6] = 0x00;
    Hexa_Val[5] = 0x00;
    Hexa_Val[4] = 0x00;
    Hexa_Val[3] = 0x00;
    Hexa_Val[2] = 0x00;
    Hexa_Val[1] = 0x00;           
  }

  if((Hexa_Val[7] = 0xFF) &amp;&amp; (Hexa_Val[6] = 0xFF) &amp;&amp; (Hexa_Val[5] = 0xFF) &amp;&amp; (Hexa_Val[4] = 0xFF) &amp;&amp; (Hexa_Val[3] = 0xFF) &amp;&amp; (Hexa_Val[2] = 0xFF) &amp;&amp; (Hexa_Val[1] = 0xFF)  &amp;&amp; (Hexa_Val[0] = 0xFF)){
    Hexa_Val[7] = 0x00;
    Hexa_Val[6] = 0x00;
    Hexa_Val[5] = 0x00;
    Hexa_Val[4] = 0x00;
    Hexa_Val[3] = 0x00;
    Hexa_Val[2] = 0x00;
    Hexa_Val[1] = 0x00;
    Hexa_Val[0] = 0x00;           
  }

  //to find out what I am sending 
  for( byte a=0; a&lt;8; a++ ) {
    Serial.print(Hexa_Val[a], HEX);
  }
  Serial.println(); 

  delay(500);

}
</code></pre>
<p>But it just gives me zeros in the serial monitor. If I just leave the first two IF statements</p>
<pre><code>byte Hexa_Val[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 

void setup() {
  Serial.begin(115200);
}

void loop() {

  Hexa_Val[7] = Hexa_Val[7] + 1;

  if(Hexa_Val[7] = 0xFF){
    Hexa_Val[6] = Hexa_Val[6] + 1;
    Hexa_Val[7] = 0x00;    
  }

  if((Hexa_Val[7] = 0xFF) &amp;&amp; (Hexa_Val[6] = 0xFF)){
    Hexa_Val[5] = Hexa_Val[5] + 1;
    Hexa_Val[7] = 0x00;
    Hexa_Val[6] = 0x00;      
  }

  //to find out what I am sending 
  for( byte a=0; a&lt;8; a++ ) {
    Serial.print(Hexa_Val[a], HEX);
  }
  Serial.println(); 

  delay(500);

}
</code></pre>
<p>The increment will start from the third value on the right. Something like</p>
<pre><code>00000200
00000300
00000400
00000500
00000600
00000700
</code></pre>
<p>How do I get it to increase as I mentioned at the beginning? Why does the code recognize <code>0xFF</code> as a zero?</p>
 7508: <p>There are multiple problems here:</p>
<blockquote>
<p><code>if(Hexa_Val[7] = 0xFF)</code></p>
</blockquote>
<p>First of all, <code>=</code> is the assignment operator. You are setting
<code>Hexa_Val[7]</code> to <code>0xFF</code>. If you want to compare for equality, you should
use <code>==</code>.</p>
<p>Second problem, The value <code>0xff</code> will never be displayed, because you
are replacing it by zero. This byte will then count 0xfd, 0xfe, 0x00,
skipping 0xff. If you want to count 0xff, the condition should be
<code>Hexa_Val[7] == 0</code>, i.e. increment <code>Hexa_Val[6]</code> only after
<code>Hexa_Val[7]</code> has overflowed.</p>
<p>Third problem, your second <code>if</code> test comes too late. At this point
<code>Hexa_Val[7]</code> has already been reset. You should test for <code>Hexa_Val[6]</code>
overflowing only <em>within</em> the previous test.</p>
<p>With all that fixed:</p>
<pre class="lang-cpp prettyprint-override"><code>Hexa_Val[7] = Hexa_Val[7] + 1;
if (Hexa_Val[7] == 0) {
  Hexa_Val[6] = Hexa_Val[6] + 1;
  if (Hexa_Val[6] == 0) {
    Hexa_Val[5] = Hexa_Val[5] + 1;
  }
}
</code></pre>
<p>If you don't want to write 8 nested conditions (which is kind of
cumbersome), you can instead loop over the array backwards, incrementing
each element in turn, and break out of the loop as soon as an increment
does <em>not</em> overflow:</p>
<pre class="lang-cpp prettyprint-override"><code>for (int i = 7; i &gt;= 0; i--) {
    if (++Hexa_Val[i] != 0) break;
}
</code></pre>
<p>If you don't mind the array being backwards, you can also handle the
whole array as a single 64-bit number, and just increment it like you
would increment any integer. But then you have to print the array
backwards, starting from the mast element:</p>
<pre class="lang-cpp prettyprint-override"><code>union {
    uint64_t number;
    byte bytes[8];
} Hexa_Val = { .number = 0 };

void loop() {
    // Increment the array.
    Hexa_Val.number++;

    // Print out.
    for (int i = 7; i &gt;= 0; i--) {
        if (Hexa_Val.bytes[i] &lt; 0x10) Serial.write('0');
        Serial.print(Hexa_Val.bytes[i], HEX);
        Serial.write(' ');
    }
    Serial.println(); 

    delay(500);
}
</code></pre>
