 |
|
|  |
10Áø¼ö < - > 16Áø¼ö º¯È¯±â PHP¼Ò½º |
|
|
 |
7´Þ Àü |
¾Æ·¡´Â PHP 5.x ¹öÀü¿¡¼ ½ÇÇà °¡´ÉÇÑ 10Áø¼ö¿Í 16Áø¼ö °£ÀÇ º¯È¯À» ¼öÇàÇÏ´Â Äڵ带 Æ÷ÇÔÇÑ Àüü À¥ ÆäÀÌÁö ¼Ò½ºÄÚµåÀÔ´Ï´Ù. ÀÌ ÄÚµå´Â °£´ÜÇÑ HTML Æû°ú CSS·Î µðÀÚÀεǾî ÀÖÀ¸¸ç, ÀÔ·ÂµÈ 10Áø¼ö ¼ýÀÚ¸¦ 16Áø¼ö·Î º¯È¯Çϰųª, ÀÔ·ÂµÈ 16Áø¼ö ¼ýÀÚ¸¦ 10Áø¼ö·Î º¯È¯ÇÒ ¼ö ÀÖ½À´Ï´Ù.
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>Decimal <-> Hexadecimal Converter</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
width: 300px;
text-align: center;
}
h2 {
margin-bottom: 20px;
color: #333;
}
input[type="text"] {
width: 80%;
padding: 10px;
margin-bottom: 10px;
border: 1px solid #ddd;
border-radius: 5px;
}
input[type="submit"] {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
}
input[type="submit"]:hover {
background-color: #45a049;
}
.result {
margin-top: 20px;
font-weight: bold;
}
</style>
</head>
<body>
<div class="container">
<h2>10Áø¼ö <-> 16Áø¼ö º¯È¯±â</h2>
<form method="post">
<input type="text" name="decimal" placeholder="10Áø¼ö¸¦ ÀÔ·ÂÇϼ¼¿ä" value="<?php echo isset($_POST['decimal']) ? htmlspecialchars($_POST['decimal']) : ''; ?>">
<input type="submit" name="to_hex" value="10Áø¼ö -> 16Áø¼ö">
<br>
<input type="text" name="hex" placeholder="16Áø¼ö¸¦ ÀÔ·ÂÇϼ¼¿ä" value="<?php echo isset($_POST['hex']) ? htmlspecialchars($_POST['hex']) : ''; ?>">
<input type="submit" name="to_decimal" value="16Áø¼ö -> 10Áø¼ö">
</form>
<div class="result">
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['to_hex']) && !empty($_POST['decimal'])) {
$decimal = $_POST['decimal'];
if (is_numeric($decimal)) {
$hex = dechex($decimal);
echo "10Áø¼ö {$decimal}´Â 16Áø¼ö·Î {$hex} ÀÔ´Ï´Ù.";
} else {
echo "À¯È¿ÇÑ 10Áø¼ö¸¦ ÀÔ·ÂÇϼ¼¿ä.";
}
} elseif (isset($_POST['to_decimal']) && !empty($_POST['hex'])) {
$hex = $_POST['hex'];
if (ctype_xdigit($hex)) {
$decimal = hexdec($hex);
echo "16Áø¼ö {$hex}´Â 10Áø¼ö·Î {$decimal} ÀÔ´Ï´Ù.";
} else {
echo "À¯È¿ÇÑ 16Áø¼ö¸¦ ÀÔ·ÂÇϼ¼¿ä.";
}
}
}
?>
</div>
</div>
</body>
</html>
$_SERVER['REQUEST_METHOD']¸¦ »ç¿ëÇÏ¿© ÆûÀÌ Á¦ÃâµÇ¾ú´ÂÁö È®ÀÎÇÕ´Ï´Ù.
is_numeric() ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© 10Áø¼ö ÀÔ·ÂÀÌ À¯È¿ÇÑ ¼ýÀÚÀÎÁö È®ÀÎÇÕ´Ï´Ù.
ctype_xdigit() ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© 16Áø¼ö ÀÔ·ÂÀÌ À¯È¿ÇÑ 16Áø¼öÀÎÁö È®ÀÎÇÕ´Ï´Ù.
dechex() ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© 10Áø¼ö¸¦ 16Áø¼ö·Î º¯È¯ÇÏ°í, hexdec() ÇÔ¼ö¸¦ »ç¿ëÇÏ¿© 16Áø¼ö¸¦ 10Áø¼ö·Î º¯È¯ÇÕ´Ï´Ù. |
|
̵̧ : 35 |
̵̧
¸ñ·Ï
|
|
|  |
|