Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

bitwise XOR with bitmask

Posted on 2004-10-14
2
Medium Priority
?
1,103 Views
Last Modified: 2012-08-14
hi .

I have 3 strings : $reg_reply , $reg_expected , $reg_mask :

register read reply       = "abcd0123" , the reply from the device
expected replied data = "abcd0023" , the expected data to be replied from the device .
reg_mask   = "ffff00ff" , the bits that should match .(the other bits are ignored in the comparison)

in verilog/vhdl I could do this ,in this way : (reply BITWISE_XOR expected) AND (mask) == 0
if TRUE : good reply
if FALSE : bad reply .

this perl code I used :

if (($reg_reply ^ $reg_data) && ($reg_mask) == 0) {
    print "REG_REPLY correct ,reply= 0x$reg_reply ,expected= 0x$reg_data ,mask= 0x$reg_mask\n";
} else {
    print "REG_REPLY ERROR wrong value,reply= 0x$reg_reply ,expected= 0x$reg_data ,mask= 0x$reg_mask\n";
}

example :

Argument "ffff000c" isn't numeric in eq at ctrl_sim.pm line 126.
REG_REPLY correct ,reply= 0xabcd0008 ,expected= 0xabcb0008 ,mask= 0xffff000c
 this should be ERROR (abcd != abcb)

and in addition , I need to remove the WARNING (Argument "ffff000c" isn't numer ...)

thanks ,

tal
0
Comment
Question by:Talmash
2 Comments
 
LVL 12

Accepted Solution

by:
stefan73 earned 200 total points
ID: 12307075
Hi Talmash,
> if (($reg_reply ^ $reg_data) && ($reg_mask) == 0) {
Are you sure you want to use logical and? Try this instead:

if ((($reg_reply ^ $reg_data) & ($reg_mask)) == 0) {

Convert your hex strings to a numeric value with the hex() function first.
Cheers!

Stefan
0
 
LVL 6

Author Comment

by:Talmash
ID: 12308204
excellent and on time .

thanks , stefan .

tal
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question