diff --git a/include/Spyc.php b/include/Spyc.php
index e92a4becea0016682299529c3fe290a44cdd21d2..33dfca9074fc1eaa7d30657399110ad2003a1895 100644
--- a/include/Spyc.php
+++ b/include/Spyc.php
@@ -615,10 +615,12 @@ class Spyc {
       return false;
     }
 
+    if (is_string($value) && preg_match('/^0x[0-9a-fA-F]+$/', $value)) {
+      return hexdec($value);
+    }
+
     if (is_numeric($value)) {
       if ($value === '0') return 0;
-      if (stripos($value, '0x') === 0)
-        $value = hexdec($value);
       if (rtrim ($value, 0) === $value)
         $value = (float)$value;
       return $value;