Horje Website
PHP Convert a Number from One Base to Another – Learn Convert a number from one base to another – PHP Code

PHP Convert a Number from One Base to Another – Learn Convert a number from one base to another

PHP Convert a Number from One Base to Another - Learn Convert a number from one base to another - PHP Code


 
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>PHP Convert a Number from One Base to Another</title>
  5. </head>
  6. <body>
  7. <?php
  8. // Convert decimal to binary
  9. echo base_convert('12', 10, 2) . "<br>"; // 0utputs: 1100
  10. // Convert binary to decimal
  11. echo base_convert('1100', 2, 10) . "<br>"; // 0utputs: 12
  12. // Convert decimal to hexadecimal
  13. echo base_convert('10889592', 10, 16) . "<br>"; // 0utputs: a62978
  14. // Convert hexadecimal to decimal
  15. echo base_convert('a62978', 16, 10) . "<br>"; // 0utputs: 10889592
  16. // Convert decimal to octal
  17. echo base_convert('82', 10, 8) . "<br>"; // 0utputs: 122
  18. // Convert octal to decimal
  19. echo base_convert('122', 8, 10) . "<br>"; // 0utputs: 82
  20. // Convert hexadecimal to octal
  21. echo base_convert('c2c6a8', 16, 8) . "<br>"; // 0utputs: 60543250
  22. // Convert octal to hexadecimal
  23. echo base_convert('60543250', 8, 16) . "<br>"; // 0utputs: c2c6a8
  24. // Convert octal to binary
  25. echo base_convert('42', 8, 2) . "<br>"; // 0utputs: 100010
  26. // Convert binary to octal
  27. echo base_convert('100010', 2, 8) . "<br>"; // 0utputs: 42
  28. // Convert hexadecimal to binary
  29. echo base_convert('abc', 16, 2) . "<br>"; // 0utputs: 101010111100
  30. // Convert binary to hexadecimal
  31. echo base_convert('101010111100', 2, 16); // 0utputs: abc
  32. ?>
  33. </body>
  34. </html>



Try Your Self ->



Published:
September 25, 2020
Author:
admin
Category:
PHP Basic, PHP Source Code
Views:
21

This article was posted in PHP Basic, PHP Source Code and tagged , , . Bookmark the permalink. Follow comments with the RSS feed for this post.Post a Comment or leave a trackback: Trackback URL.

Leave a Reply

Your email address will not be published. Required fields are marked *

 

Horje © 2011 - 2023