wondering if anyone might have some insight or point me to the proper documentation explaining the following line of code:
byte flag = (byte) (flagOfCardData&0x04);
I don’t have any clue as to why there is the &0x04 after flagOfCardData. I know it has to do with something hexadecimal but that is it. Here it the line of code as it sits in the function.
public void onReceiveMsgCardData(byte flagOfCardData,byte[] cardData) {
// TODO Auto-generated method stub
byte flag = (byte) (flagOfCardData&0x04);
if(flag==0x00)
_strMSRData = new String (cardData);
if(flag==0x04)
{
//You need to dencrypt the data here first.
_strMSRData = new String (cardData);
}
_MSRData = null;
_MSRData = new byte[cardData.length];
System.arraycopy(cardData, 0, _MSRData, 0, cardData.length);
_isCardData = true;
handler.post(doHideTopDlg);
handler.post(doHideSwipeTopDlg);
handler.post(doUpdateTVS);
}
I would look up why to do this but I can’t even figure out the right search keywords DOH! Thanks for any and all help.
This is for Android sdk using eclipse and java. Also, the code is part of another sdk that is part of a magnetic card reader that connects to an Android powered device through the audio port. The product is called unimag pro. Here is the website: http://www.idtechproducts.com/products/mobile-readers/126.html
I did send them the same question but who knows if and when they might respond. I will post their answer on here as well for anyone else that might come across the same problem.
Let me know if you need any more info.
Thanks.
Your
flagOfCardDatais an 8-bit integer, but each bit individually is assigned some independent meaning. In your case, you only want to know its second bit. To do so, you perform bitwise-and with 00000100b, which is 4:Now
Xis1if the second bit is set (1 & 1 = 1), and0otherwise (1 & 0 = 0). ThusflagOfCardData & 0x04is eiter 4 or 0 accordingly.It’s customary to just use hexadecimal notation for the individual bits: