Pages: [1]   Go Down
Author Topic: RFID Wiegand Interface Bit Manipulation and Masks  (Read 441 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 43
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Gang

I am trying to extract serial number from a RFID bracelet using a Wiegand Interface. I have read that I need to use a combination of bit manipulation and masks. I have been able to get my head around bit manipulation but I'm having trouble with masks.

If for example I have the following raw code;

1 0110 1101 0101 1000 0011 1111 0

And I want to remove the right most bit, I simply use bit manipulation;

rawCode >> 1

This moves all bits one step to the right leaving me with;

1 0110 1101 0101 1000 0011 1111

If however I'm only interested in the remaining last 24 bits then I believe I need to use a mask;

0xFFFFFF

Specifically I need to combine bit manipulation and mask to extract the serial number;

serialNumber = (rawCode >> 1) & 0xFFFFFF

I don't understand the syntax for the mask;

0xFFFFFF

The 'F' I assume is a hexadecimal, therefore FFFFFF represents 24 bits. I don't get the 0x???

Can someone possibly explain?

Cheers

Jase  smiley





Logged

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 66
Posts: 2116
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

literals in c/c++ use a prefix to distinguish between decimal, binary, and hexidecimal numbers.

0x is for hex

0b is for binary

decimal has no prefix.

numbers can have suffix's too denoting type,

float: 1.23f
long: 123456L
unsigned long: 123456UL
etc...

as for masks and bit manipulation, there are many articles on this exact issure here on the forums and web-wide

« Last Edit: January 22, 2013, 07:25:06 am by pYro_65 » Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 43
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi pYro_65

Thanks for the reply. I think I understand so 0x is a prefix to the literal FFFFFF. So it's basically saying what to expect the mask to be, in this case a hexadecimal. I could alternatively write this as 0b1111 1111 1111 1111 1111 1111?

Cheers

Jase
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Without the spaces.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 43
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Nick

Much appreciated.

Cheers

Jason smiley
Logged

Pages: [1]   Go Up
Jump to: