user42957: Hello everyone i'm figuring if this variable can be passed to another variable. I'm using RFID RC522
Here is the code:
 #include <SPI.h>
    #include <MFRC522.h>
    #define RST_PIN         5           // Configurable, see typical pin layout 
    above
    #define SS_PIN          53          // Configurable, see typical pin layout 
    above
    MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.
    int result = 0;
    // Number of known default keys (hard-coded)
    // NOTE: Synchronize the NR_KNOWN_KEYS define with the defaultKeys[] array
    #define NR_KNOWN_KEYS   8
    // Known keys, see: 
    https://code.google.com/p/mfcuk/wiki/MifareClassicDefaultKeys
    byte knownKeys[NR_KNOWN_KEYS][MFRC522::MF_KEY_SIZE] =  {
    {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, // FF FF FF FF FF FF = factory default
    {0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5}, // A0 A1 A2 A3 A4 A5
    {0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5}, // B0 B1 B2 B3 B4 B5
    {0x4d, 0x3a, 0x99, 0xc3, 0x51, 0xdd}, // 4D 3A 99 C3 51 DD
    {0x1a, 0x98, 0x2c, 0x7e, 0x45, 0x9a}, // 1A 98 2C 7E 45 9A
    {0xd3, 0xf7, 0xd3, 0xf7, 0xd3, 0xf7}, // D3 F7 D3 F7 D3 F7
    {0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}, // AA BB CC DD EE FF
    {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}  // 00 00 00 00 00 00
    };
    /*
    * Initialize.
    */
    void setup() {
    Serial.begin(9600);         // Initialize serial communications with the PC
    while (!Serial);            // Do nothing if no serial port is opened (added 
    for Arduinos based on ATMEGA32U4)
    SPI.begin();                // Init SPI bus
    mfrc522.PCD_Init();         // Init MFRC522 card
    // Serial.println(F("Try the most used default keys to print block 0 of a 
    MIFARE PICC."));
    }
    /*
    * Helper routine to dump a byte array as hex values to Serial.
    */
    void dump_byte_array(byte *buffer, byte bufferSize) {
    for (byte i = 0; i < bufferSize; i++) {
    Serial.print(buffer[i] < 0x10 ? " 0" : " ");
        Serial.print(buffer[i], HEX);
    }
}

/*
 * Try using the PICC (the tag/card) with the given key to access block 0.
 * On success, it will show the key details, and dump the block data on Serial.
 *
 * @return true when the given key worked, false otherwise.
 */
boolean try_key(MFRC522::MIFARE_Key *key)
{
    boolean result = false;
    byte buffer[18];
    byte block = 0;
    byte status;

    // Serial.println(F("Authenticating using key A..."));
    status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, key, &(mfrc522.uid));
    if (status != MFRC522::STATUS_OK) {
        // Serial.print(F("PCD_Authenticate() failed: "));
        // Serial.println(mfrc522.GetStatusCodeName(status));
        return false;
    }

    // Read block
    byte byteCount = sizeof(buffer);
    status = mfrc522.MIFARE_Read(block, buffer, &byteCount);
    if (status != MFRC522::STATUS_OK) {
        // Serial.print(F("MIFARE_Read() failed: "));
        // Serial.println(mfrc522.GetStatusCodeName(status));
    }
    else {
        // Successful read
        result = true;
        //Serial.print(F("Success with key:"));
        dump_byte_array((*key).keyByte, MFRC522::MF_KEY_SIZE);
        //Serial.println();
        // Dump block data
       // Serial.print(F("Block ")); Serial.print(block); Serial.print(F(":"));
        dump_byte_array(buffer, 16);
        //Serial.println();
    }
  //  Serial.println();

    mfrc522.PICC_HaltA();       // Halt PICC
    mfrc522.PCD_StopCrypto1();  // Stop encryption on PCD
    return result;
}

/*
 * Main loop.
 */
void loop() {
  // Look for new cards
    if ( ! mfrc522.PICC_IsNewCardPresent())
        return;
// Select one of the cards
    if ( ! mfrc522.PICC_ReadCardSerial())
    return;
    // Show some details of the PICC (that is: the tag/card)
   // Serial.print(F("Card UID:"));
    dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
delay(3000); 
// Serial.print(F("PICC type: "));
  //  byte piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
    //Serial.println(mfrc522.PICC_GetTypeName(piccType));

    // Try the known default keys

      }

I list all of my card's value and i want to create a conditional statement if the result of dump_byte_array is the same with my card's value i list.
Sample:
if ( dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size) && "D4 39 F8 BE" == 
  true ){
        Serial.print("Card 1 Detected");

That's what i want to happen but i know that is wrong.
Please help me with this.
Thank you in advance.

user21371: Simply rewrite your dump_byte_array function as follows
bool matchID(byte *buffer, byte bufferSize, byte * match, byte matchSize) {
    if (bufferSize != matchSize) return false;
    for (byte i = 0; i < bufferSize; i++)
        if (buffer[i] != match[i]) 
            return false;
    return true;
}

and call this new function like
if ( matchID(mfrc522.uid.uidByte, mfrc522.uid.size, [0xD4, 0x39, 0xF8, 0xBE], 4)) {
    Serial.print("Card 1 Detected");
}

As suggested in the comments, what's wrong with memcmp ...
bool matchID(byte *buffer, byte bufferSize, byte * match, byte matchSize) {
    if (bufferSize != matchSize) return false;
    return memcmp(buffer, match, bufferSize) == 0;
}


user-1: Well, dump_byte_array is a void function, so you can't compare it to anything.
And this line
if (dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size) && "D4 39 F8 BE" == true)

is both ilegal and illogical. Ilegal, because you are comparing a pointer ("
("D4 39 F8 BE") against an integer (the true value is a int in disguise).
It's illogical, because you are "&&" is the logical and operator, not the bitwise and.
What you need is a string comparison:
if (strncmp(mfrc522.uid.uidByte, "D4 39 F8 BE", mfrc522.uid.size) == 0) {
   Serial.println("Card found");
}

That's assuming that uidByte contains the ID.
The strncmp function
int strncmp ( const char * str1, const char * str2, size_t num );

Compare characters of two strings
Compares up to num characters of the C string str1 to those of the C string str2.
This function starts comparing the first character of each string. If they are equal to each other, it continues with the following pairs until the characters differ, until a terminating null-character is reached, or until num characters match in both strings, whichever happens first.
Parameters
str1     C string to be compared.
str2     C string to be compared.
num      Maximum number of characters to compare. size_t is an unsigned integral type.
Return Value
Returns an integral value indicating the relationship between the strings:

<0   the first character that does not match has a lower value in str1
than in str2
0    the contents of both strings are equal
>0  the first character that does not match has a greater value in str1 than in str2

But you really need to learn C.

42957: <p>Hello everyone i'm figuring if this variable can be passed to another variable. I'm using RFID RC522
Here is the code:</p>

<pre><code> #include &lt;SPI.h&gt;
    #include &lt;MFRC522.h&gt;
    #define RST_PIN         5           // Configurable, see typical pin layout 
    above
    #define SS_PIN          53          // Configurable, see typical pin layout 
    above
    MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.
    int result = 0;
    // Number of known default keys (hard-coded)
    // NOTE: Synchronize the NR_KNOWN_KEYS define with the defaultKeys[] array
    #define NR_KNOWN_KEYS   8
    // Known keys, see: 
    https://code.google.com/p/mfcuk/wiki/MifareClassicDefaultKeys
    byte knownKeys[NR_KNOWN_KEYS][MFRC522::MF_KEY_SIZE] =  {
    {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, // FF FF FF FF FF FF = factory default
    {0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5}, // A0 A1 A2 A3 A4 A5
    {0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5}, // B0 B1 B2 B3 B4 B5
    {0x4d, 0x3a, 0x99, 0xc3, 0x51, 0xdd}, // 4D 3A 99 C3 51 DD
    {0x1a, 0x98, 0x2c, 0x7e, 0x45, 0x9a}, // 1A 98 2C 7E 45 9A
    {0xd3, 0xf7, 0xd3, 0xf7, 0xd3, 0xf7}, // D3 F7 D3 F7 D3 F7
    {0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}, // AA BB CC DD EE FF
    {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}  // 00 00 00 00 00 00
    };
    /*
    * Initialize.
    */
    void setup() {
    Serial.begin(9600);         // Initialize serial communications with the PC
    while (!Serial);            // Do nothing if no serial port is opened (added 
    for Arduinos based on ATMEGA32U4)
    SPI.begin();                // Init SPI bus
    mfrc522.PCD_Init();         // Init MFRC522 card
    // Serial.println(F("Try the most used default keys to print block 0 of a 
    MIFARE PICC."));
    }
    /*
    * Helper routine to dump a byte array as hex values to Serial.
    */
    void dump_byte_array(byte *buffer, byte bufferSize) {
    for (byte i = 0; i &lt; bufferSize; i++) {
    Serial.print(buffer[i] &lt; 0x10 ? " 0" : " ");
        Serial.print(buffer[i], HEX);
    }
}

/*
 * Try using the PICC (the tag/card) with the given key to access block 0.
 * On success, it will show the key details, and dump the block data on Serial.
 *
 * @return true when the given key worked, false otherwise.
 */
boolean try_key(MFRC522::MIFARE_Key *key)
{
    boolean result = false;
    byte buffer[18];
    byte block = 0;
    byte status;

    // Serial.println(F("Authenticating using key A..."));
    status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, key, &amp;(mfrc522.uid));
    if (status != MFRC522::STATUS_OK) {
        // Serial.print(F("PCD_Authenticate() failed: "));
        // Serial.println(mfrc522.GetStatusCodeName(status));
        return false;
    }

    // Read block
    byte byteCount = sizeof(buffer);
    status = mfrc522.MIFARE_Read(block, buffer, &amp;byteCount);
    if (status != MFRC522::STATUS_OK) {
        // Serial.print(F("MIFARE_Read() failed: "));
        // Serial.println(mfrc522.GetStatusCodeName(status));
    }
    else {
        // Successful read
        result = true;
        //Serial.print(F("Success with key:"));
        dump_byte_array((*key).keyByte, MFRC522::MF_KEY_SIZE);
        //Serial.println();
        // Dump block data
       // Serial.print(F("Block ")); Serial.print(block); Serial.print(F(":"));
        dump_byte_array(buffer, 16);
        //Serial.println();
    }
  //  Serial.println();

    mfrc522.PICC_HaltA();       // Halt PICC
    mfrc522.PCD_StopCrypto1();  // Stop encryption on PCD
    return result;
}

/*
 * Main loop.
 */
void loop() {
  // Look for new cards
    if ( ! mfrc522.PICC_IsNewCardPresent())
        return;
// Select one of the cards
    if ( ! mfrc522.PICC_ReadCardSerial())
    return;
    // Show some details of the PICC (that is: the tag/card)
   // Serial.print(F("Card UID:"));
    dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
delay(3000); 
// Serial.print(F("PICC type: "));
  //  byte piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
    //Serial.println(mfrc522.PICC_GetTypeName(piccType));

    // Try the known default keys

      }
</code></pre>

<p>I list all of my card's value and i want to create a conditional statement if the result of dump_byte_array is the same with my card's value i list.
Sample:</p>

<pre><code>if ( dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size) &amp;&amp; "D4 39 F8 BE" == 
  true ){
        Serial.print("Card 1 Detected");
</code></pre>

<p>That's what i want to happen but i know that is wrong.
Please help me with this.
Thank you in advance.</p>
 21371: <p>Simply rewrite your dump_byte_array function as follows</p>

<pre><code>bool matchID(byte *buffer, byte bufferSize, byte * match, byte matchSize) {
    if (bufferSize != matchSize) return false;
    for (byte i = 0; i &lt; bufferSize; i++)
        if (buffer[i] != match[i]) 
            return false;
    return true;
}
</code></pre>

<p>and call this new function like</p>

<pre><code>if ( matchID(mfrc522.uid.uidByte, mfrc522.uid.size, [0xD4, 0x39, 0xF8, 0xBE], 4)) {
    Serial.print("Card 1 Detected");
}
</code></pre>

<p>As suggested in the comments, what's wrong with memcmp ...</p>

<pre><code>bool matchID(byte *buffer, byte bufferSize, byte * match, byte matchSize) {
    if (bufferSize != matchSize) return false;
    return memcmp(buffer, match, bufferSize) == 0;
}
</code></pre>
 -1: <p>Well, <code>dump_byte_array</code> is a void function, so you can't compare it to anything.</p>

<p>And this line</p>

<pre><code>if (dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size) &amp;&amp; "D4 39 F8 BE" == true)
</code></pre>

<p>is both ilegal and illogical. Ilegal, because you are comparing a pointer ("
("D4 39 F8 BE") against an integer (the <em>true</em> value is a int in disguise).</p>

<p>It's illogical, because you are "&amp;&amp;" is the <strong>logical and</strong> operator, not the bitwise <em>and</em>.</p>

<p>What you need is a string comparison:</p>

<pre><code>if (strncmp(mfrc522.uid.uidByte, "D4 39 F8 BE", mfrc522.uid.size) == 0) {
   Serial.println("Card found");
}
</code></pre>

<p>That's assuming that uidByte contains the ID.</p>

<p><strong>The strncmp function</strong></p>

<pre><code>int strncmp ( const char * str1, const char * str2, size_t num );
</code></pre>

<p><em>Compare characters of two strings</em></p>

<p>Compares up to num characters of the C string str1 to those of the C string str2.</p>

<p>This function starts comparing the first character of each string. If they are equal to each other, it continues with the following pairs until the characters differ, until a terminating null-character is reached, or until num characters match in both strings, whichever happens first.</p>

<p><em>Parameters</em></p>

<p>str1     C string to be compared.</p>

<p>str2     C string to be compared.</p>

<p>num      Maximum number of characters to compare. size_t is an unsigned integral type.</p>

<p><em>Return Value</em></p>

<p>Returns an integral value indicating the relationship between the strings:</p>

<ul>
<li><p>&lt;0   the first character that does not match has a lower value in str1
than in str2</p></li>
<li><p>0    the contents of both strings are equal</p></li>
<li><p>>0  the first character that does not match has a greater value in str1 than in str2</p></li>
</ul>

<p>But you really need to learn C.</p>
