-
October 5th, 2011, 11:25 AM
#1
Bitwise Hex
Hello
I'm newbie here
I'm developing a GUI to manipulate the RS232 with a MyFARE Card Reader (some kind of RFID reader)
I order to write or to read a block from the card, I send Hex message like "16 00 49 ab 47 xx" where xx is the checksum (the bitwise in Hex) of all other numbers (so : 16, 00, 49, 47)
I Google it but all I can find is bitwise in binary not in hex, someone suggested that I convert all my numbers from hex to bin then do the bitwise with the '|' operator then convert back to hex .... I tried but actually never succeed it.
So is there anyway to manage this problem for me ?
I resume :
Input : 16 00 49 ab 47
output : the checksum of input
16 = 00010110
49 = 01001001
47 = 01000111
======================== (XOR columns)
x = 00011000 = 18
thanks in advance
PS: i'm using Visual 2010
Last edited by papriko; October 5th, 2011 at 04:15 PM.
-
October 5th, 2011, 11:29 AM
#2
Re: Bitwise Hex
4th line I mean "In order to ....
ps : how do I edit my post ?
-
October 5th, 2011, 02:33 PM
#3
Re: Bitwise Hex
There should be an edit button in the right bottom corner of your posts.
Is this a school-assignment?
The example you showed is wrong. The result is 0x18 not 0x14.
The xor operator is ^ not | (or operator).
Last edited by S_M_A; October 5th, 2011 at 03:18 PM.
-
October 5th, 2011, 03:05 PM
#4
Re: Bitwise Hex
In reality, the correct result (checksum) is B3.
0001 0110 (16)
0000 0000 (00)
0100 1001 (49)
1010 1011 (ab)
0100 0111 (47)
---------
1011 0011
You must XOR all of the values: 16 00 49 ab 47 (yes, ab is a value that needs to be included).
Good luck.
Last edited by krmed; October 5th, 2011 at 03:08 PM.
Be sure to rate those who help!
-------------------------------------------------------------
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
-
October 5th, 2011, 04:17 PM
#5
Re: Bitwise Hex
S_M_A
No this is not a school assignment and yes I was wrong it's 18 not 14
krmed
I know what XOR is , I need it to work with Hex !
-
October 5th, 2011, 04:19 PM
#6
Re: Bitwise Hex
yeah another error pfff stupid I am
i miss the term ab
anyway I need the bitwise (XOR) to work with hex not binarys
-
October 6th, 2011, 01:00 AM
#7
Re: Bitwise Hex
Can you explain what you mean with "binary, not in hex"?
Hex is a numeral system, it represents values. Anyway all the values in your computer are still binaries (they consist of zero's and one's).
Code:
__int32 a = 18;
printf("dec = %d hex = 0x%0x\n", a, a);
shoud print:
12 0x0c
Both numerals represent the same value which is:
0000 0000 0001 0010
The bitwise(sic!) xor operator in c/c++ is ^.
The name of the RFID card is Mifare.
-
October 6th, 2011, 05:58 AM
#8
Re: Bitwise Hex
Originally Posted by papriko
S_M_A
No this is not a school assignment and yes I was wrong it's 18 not 14
krmed
I know what XOR is , I need it to work with Hex !
Acutally you are not correct here - the checksum is not 18 as you say - it should be B3 as mentioned in my earlier post.
The data you show is quoted, so I'm assuming you are wanting to send a string of characters (i.e. "16 00 49 ab 47") to your device, but you need the checksum. This being the case, you need to get your string into variables so you can use the xor on the. You might want to have something like
Code:
unsigned char first = 0;
unsigned char second = 0;
unsigned char third = 0;
unsigned char fourth = 0;
unsigned char fifth = 0;
unsigned char checksum = 0;
Now you need to convert your string to put the values in the variable - perhaps sscanf can be your friend.
Now you can calculate your checksum:
Code:
checksum = first ^ second ^ third ^ fourth ^ fifth;
Hex is simply a way to display the data - it's still binary data just as shown before.
Hope that helps.
Be sure to rate those who help!
-------------------------------------------------------------
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
-
October 6th, 2011, 06:50 AM
#9
Re: Bitwise Hex
thank you all guys , i'm gonna try what you said krmed in the last post
if something goes wrong i'll be back , I know i'm being annoying sorry !!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|