/** * Detect if an integer is binary or not * Uses some nifty bit-hackery. * If i is even then i & ( i - 1 ) == 0 * Look at that in base 2, it's neat to see it in action :) * @param int $i Integer to test * @return boolean is base 2 * @static */ public static function isBase2($i) { if (!EDataType::isInt($i)) { return false; } return $i != 0 && ($i & $i - 1) == 0; }
/** * Create a new IntStr instance * @param int $int Int * @param string $str String * @throws InvalidArgumentException if int is not an integer */ public static function create($int, $str) { if (!EDataType::isInt($int)) { throw new InvalidArgumentException('int must be an integer'); } if (empty($str)) { $str = (string) $int; } $c = __CLASS__; return new $c($int, $str); }
/** * Create a new IDataType instance based on the value of $val * @param mixed $val Value * @return IDataType instance * @static */ public static function create($val) { $i = new EDataType(); $i->setValue($i->detectType($val)); return $i; }
/** * Sets the units. defaults to "px" * @param string $units Units */ public function setUnits($units) { if (empty($units) || EDataType::isInt($units)) { $units = 'px'; } $this->units = $units; }
/** * Sets the value * @param int $value Value * @throws InvalidArgumentException if $value is not an integer */ public function setValue($value) { $parts = explode(' ', $value); if (empty($parts)) { return ''; } if (isset($parts[0])) { if (!EDataType::isInt((int) $parts[0])) { throw new InvalidArgumentException("value must be an integer"); } $this->value = (int) $parts[0]; } if (isset($parts[1])) { $this->setUnits($parts[1]); } }