Home  >  Article  >  Backend Development  >  Convert decimal to hexadecimal (base A-Z)

Convert decimal to hexadecimal (base A-Z)

WBOY
WBOYOriginal
2016-07-25 08:47:562290browse
Convert decimal to hexadecimal (base A-Z), convert decimal numbers into hexadecimal data with Z-A as base.
Used to get the index of the specified column in excel
  1. /**
  2. * Get the name index of the specified cell in the excel table:
  3. * For example, row 1, column 1:
  4. * Return A1
  5. * Row 27, second column:
  6. * Return AA1:
  7. *
  8. * @param int $row No. How many rows
  9. * @param int $col Which column
  10. *
  11. * @author mingche
  12. * @since 2014-05-31
  13. */
  14. function getExcelCeilIndex($row, $col) {
  15. if($row > 0 && $col > 0 )
  16. {
  17. $str = " ZABCDEFGHIGKLMNOPQRSTUVWXY";
  18. $col_str = "";
  19. do
  20. {
  21. $col_tmp = $col % 26;
  22. $col = $col_tmp == 0 ? intval($col / 26) - 1 : intval($col / 26) ;
  23. $col_str = $str[$col_tmp].$col_str;
  24. }while( $col );
  25. return $col_str.$row;
  26. }
  27. return false;
  28. }
  29. ?>
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn