PHP - Convert Decimal To Hexadecimal

Submitted by: 
Visitors have accessed this post 84 times.

In this tutorial we will create Convert Decimal To Hexadecimal using PHP. PHP is a server-side scripting language designed primarily for web development. Using PHP, you can let your user directly interact with the script and easily to learned its syntax. It is mostly used by a newly coders for its user friendly environment. So let's now do the coding...

Getting Started:

First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server

And this is the link for the bootstrap that i used for the layout design

Lastly, this is the link for the jquery that i used in this tutorial

Creating The Interface

This is where we will create a simple form for our application. To create the forms simply copy and write it into you text editor, then save it as index.php.

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
  5. <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
  6. </head>
  7. <body>
  8. <nav class="navbar navbar-default">
  9. <div class="container-fluid">
  10. <a class="navbar-brand" href="<a href="">Sourcecodester</a>
  11. " rel="nofollow">">Sourcecodester</a>
  12. </a> </div>
  13. </nav>
  14. <div class="col-md-3"></div>
  15. <div class="col-md-6 well">
  16. <h3 class="text-primary">PHP - Convert Decimal To Hexadecimal</h3>
  17. <hr style="border-top:1px dotted #ccc;"/>
  18. <div class="col-md-3"></div>
  19. <div class="col-md-6">
  20. <h3>Decimal to Hexadecimal</h3>
  21. <br />
  22. <div class="form-group">
  23. <label>Enter number</label>
  24. <input type="number" id="decimal" class="form-control" />
  25. </div>
  26. <button class="btn btn-primary" type="button" id="convert"><span class="glyphicon glyphicon-random"></span> Convert</button>
  27. <div id="result1"></div>
  28. </div>
  29. </div>
  30. <script src="js/jquery-3.2.1.min.js"></script>
  31. <script src="js/script.js"></script>
  32. </body>
  33. </html>

Creating the Script

This code contains the script of the application. This code use jQuery ajax to make a request to server without refreshing the form values To do that just copy and write this block of codes inside the text editor, then save it inside the js directory as script.js.

  1. $(document).ready(function(){
  2. $('#convert').on('click', function(){
  3. if($('#decimal').val() != ""){
  4. var decimal = $('#decimal').val();
  5. $.ajax({
  6. url: 'converter.php',
  7. type: 'POST',
  8. data: {decimal: decimal},
  9. success: function(data){
  10. $("#result1").html("<center><h3 class='text-success'>"+data+"</h3></center>");
  11. }
  12. });
  13. }else{
  14. alert("Please enter something!");
  15. }
  16. });
  17. });

Creating Main Function

This code contains the main function of the application. This code will convert the decimal value into a hexadecimal when the button is clicked. To do that just copy and write this block of codes inside the text editor, then save it as converter.php.

  1. <?php
  2. if(ISSET($_POST['decimal'])){
  3. $decimal = $_POST['decimal'];
  5. $converted = dechex($decimal);
  7. echo $converted;
  8. }
  9. ?>

There you have it we successfully created Convert Decimal To Hexadecimal using PHP. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.