Hi; I've been banging my head against this wall for hours and am hoping someone can be of assistance. I am new to PHP, but an experienced programmer. I need to take a hex string from a database and apply a Hex Mask The problem I'm having is getting PHP to recognize that the value from the database is an actual hex value and return something meaningful: Here's the code: //$originalhex is the value found in the database. It is typically something like: 0xF1306D7100007132 $substring = substr($originalhex,$subL,$subR); //I need to only mask certain digits...in this case I come up with 0xF13 $sdec = hexdec($substring); $shex = dechex($sdec); $maskedresult = $shex & 0x00F; //This typically returns 0, but $shex returns F13 (I cannot add 0x to it without getting an error //$maskedresult = 0xF13 & 0x00F; //This line will give me the expected result PHP: Can anyone help? Thanks!
Well, hex is still a number, isn't it? When you get $sdec, don't convert back. Use that to do bitwise AND with 0x00f, like this: $substring = substr("0xF1306D7100007132",2,3); $sdec = hexdec($substring); $maskedresult = $sdec & 0x00F; echo ($maskedresult); // I got (int) 3 Code (markup): - Rufas