@@ 1209-1238 (lines=30) @@ | ||
1206 | * |
|
1207 | * @return string |
|
1208 | */ |
|
1209 | public static function BINTOHEX($x, $places = null) |
|
1210 | { |
|
1211 | $x = Functions::flattenSingleValue($x); |
|
1212 | $places = Functions::flattenSingleValue($places); |
|
1213 | ||
1214 | // Argument X |
|
1215 | if (is_bool($x)) { |
|
1216 | if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) { |
|
1217 | $x = (int) $x; |
|
1218 | } else { |
|
1219 | return Functions::VALUE(); |
|
1220 | } |
|
1221 | } |
|
1222 | if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) { |
|
1223 | $x = floor($x); |
|
1224 | } |
|
1225 | $x = (string) $x; |
|
1226 | if (strlen($x) > preg_match_all('/[01]/', $x, $out)) { |
|
1227 | return Functions::NAN(); |
|
1228 | } |
|
1229 | if (strlen($x) > 10) { |
|
1230 | return Functions::NAN(); |
|
1231 | } elseif (strlen($x) == 10) { |
|
1232 | // Two's Complement |
|
1233 | return str_repeat('F', 8) . substr(strtoupper(dechex(bindec(substr($x, -9)))), -2); |
|
1234 | } |
|
1235 | $hexVal = (string) strtoupper(dechex(bindec($x))); |
|
1236 | ||
1237 | return self::nbrConversionFormat($hexVal, $places); |
|
1238 | } |
|
1239 | ||
1240 | /** |
|
1241 | * BINTOOCT. |
|
@@ 1265-1293 (lines=29) @@ | ||
1262 | * |
|
1263 | * @return string |
|
1264 | */ |
|
1265 | public static function BINTOOCT($x, $places = null) |
|
1266 | { |
|
1267 | $x = Functions::flattenSingleValue($x); |
|
1268 | $places = Functions::flattenSingleValue($places); |
|
1269 | ||
1270 | if (is_bool($x)) { |
|
1271 | if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) { |
|
1272 | $x = (int) $x; |
|
1273 | } else { |
|
1274 | return Functions::VALUE(); |
|
1275 | } |
|
1276 | } |
|
1277 | if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) { |
|
1278 | $x = floor($x); |
|
1279 | } |
|
1280 | $x = (string) $x; |
|
1281 | if (strlen($x) > preg_match_all('/[01]/', $x, $out)) { |
|
1282 | return Functions::NAN(); |
|
1283 | } |
|
1284 | if (strlen($x) > 10) { |
|
1285 | return Functions::NAN(); |
|
1286 | } elseif (strlen($x) == 10) { |
|
1287 | // Two's Complement |
|
1288 | return str_repeat('7', 7) . substr(strtoupper(decoct(bindec(substr($x, -9)))), -3); |
|
1289 | } |
|
1290 | $octVal = (string) decoct(bindec($x)); |
|
1291 | ||
1292 | return self::nbrConversionFormat($octVal, $places); |
|
1293 | } |
|
1294 | ||
1295 | /** |
|
1296 | * DECTOBIN. |