@@ 1127-1154 (lines=28) @@ | ||
1124 | * If places is negative, BIN2HEX returns the #NUM! error value. |
|
1125 | * @return string |
|
1126 | */ |
|
1127 | public static function BINTOHEX($x, $places=NULL) { |
|
1128 | $x = PHPExcel_Calculation_Functions::flattenSingleValue($x); |
|
1129 | $places = PHPExcel_Calculation_Functions::flattenSingleValue($places); |
|
1130 | ||
1131 | if (is_bool($x)) { |
|
1132 | if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) { |
|
1133 | $x = (int) $x; |
|
1134 | } else { |
|
1135 | return PHPExcel_Calculation_Functions::VALUE(); |
|
1136 | } |
|
1137 | } |
|
1138 | if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) { |
|
1139 | $x = floor($x); |
|
1140 | } |
|
1141 | $x = (string) $x; |
|
1142 | if (strlen($x) > preg_match_all('/[01]/',$x,$out)) { |
|
1143 | return PHPExcel_Calculation_Functions::NaN(); |
|
1144 | } |
|
1145 | if (strlen($x) > 10) { |
|
1146 | return PHPExcel_Calculation_Functions::NaN(); |
|
1147 | } elseif (strlen($x) == 10) { |
|
1148 | // Two's Complement |
|
1149 | return str_repeat('F',8).substr(strtoupper(dechex(bindec(substr($x,-9)))),-2); |
|
1150 | } |
|
1151 | $hexVal = (string) strtoupper(dechex(bindec($x))); |
|
1152 | ||
1153 | return self::_nbrConversionFormat($hexVal,$places); |
|
1154 | } // function BINTOHEX() |
|
1155 | ||
1156 | ||
1157 | /** |
|
@@ 1181-1208 (lines=28) @@ | ||
1178 | * If places is negative, BIN2OCT returns the #NUM! error value. |
|
1179 | * @return string |
|
1180 | */ |
|
1181 | public static function BINTOOCT($x, $places=NULL) { |
|
1182 | $x = PHPExcel_Calculation_Functions::flattenSingleValue($x); |
|
1183 | $places = PHPExcel_Calculation_Functions::flattenSingleValue($places); |
|
1184 | ||
1185 | if (is_bool($x)) { |
|
1186 | if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_OPENOFFICE) { |
|
1187 | $x = (int) $x; |
|
1188 | } else { |
|
1189 | return PHPExcel_Calculation_Functions::VALUE(); |
|
1190 | } |
|
1191 | } |
|
1192 | if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) { |
|
1193 | $x = floor($x); |
|
1194 | } |
|
1195 | $x = (string) $x; |
|
1196 | if (strlen($x) > preg_match_all('/[01]/',$x,$out)) { |
|
1197 | return PHPExcel_Calculation_Functions::NaN(); |
|
1198 | } |
|
1199 | if (strlen($x) > 10) { |
|
1200 | return PHPExcel_Calculation_Functions::NaN(); |
|
1201 | } elseif (strlen($x) == 10) { |
|
1202 | // Two's Complement |
|
1203 | return str_repeat('7',7).substr(strtoupper(decoct(bindec(substr($x,-9)))),-3); |
|
1204 | } |
|
1205 | $octVal = (string) decoct(bindec($x)); |
|
1206 | ||
1207 | return self::_nbrConversionFormat($octVal,$places); |
|
1208 | } // function BINTOOCT() |
|
1209 | ||
1210 | ||
1211 | /** |