<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Seven-segment display value</title>
|
|
<style>
|
|
body{
|
|
display: grid;
|
|
grid-template-columns: auto auto;
|
|
justify-items: center;
|
|
}
|
|
.display{
|
|
display: grid;
|
|
grid-template-areas:
|
|
"f a a a b x y"
|
|
"f v v v b x y"
|
|
"f v v v b x y"
|
|
"g g g g g x y"
|
|
"e w w w c x y"
|
|
"e w w w c x y"
|
|
"e d d d c x o";
|
|
height: 400px;
|
|
width: 280px;
|
|
}
|
|
.seg{
|
|
border:1px solid black;
|
|
background-color: grey;
|
|
cursor: pointer;
|
|
}
|
|
#a{
|
|
grid-area: a;
|
|
}
|
|
#b{
|
|
grid-area: b;
|
|
}
|
|
#c{
|
|
grid-area: c;
|
|
}
|
|
#d{
|
|
grid-area: d;
|
|
}
|
|
#e{
|
|
grid-area: e;
|
|
}
|
|
#f{
|
|
grid-area: f;
|
|
}
|
|
#g{
|
|
grid-area: g;
|
|
}
|
|
#v{
|
|
grid-area: v;
|
|
}
|
|
#w{
|
|
grid-area: w;
|
|
}
|
|
#o{
|
|
grid-area: o;
|
|
}
|
|
.activated{
|
|
background-color: red!important;
|
|
}
|
|
td{
|
|
font-size: large;
|
|
width: 150px;
|
|
}
|
|
td, th{
|
|
border:1px solid black;
|
|
padding: 5px;
|
|
}
|
|
table{
|
|
border-collapse: collapse;;
|
|
}
|
|
#result{
|
|
margin-top: 20px;
|
|
}
|
|
</style>
|
|
<script>
|
|
segmentValue=0;
|
|
binElem=null;
|
|
hexElem=null;
|
|
binPaddedElem=null;
|
|
hexPaddedElem=null;
|
|
window.onload=()=>{
|
|
binElem=document.getElementById("bin");
|
|
hexElem=document.getElementById("hex");
|
|
binPaddedElem=document.getElementById("binPadded");
|
|
hexPaddedElem=document.getElementById("hexPadded");
|
|
displayResult();
|
|
};
|
|
function displayResult(){
|
|
binElem.innerHTML=segmentValue;
|
|
binPadded.innerHTML=String(segmentValue).padStart(8,"0");
|
|
hexElem.innerHTML=parseInt(segmentValue,2).toString(16).toUpperCase();
|
|
hexPaddedElem.innerHTML="0x"+hexElem.innerHTML;
|
|
}
|
|
function clickSegment(elem){
|
|
elementValue=0;
|
|
switch (elem.id) {
|
|
case "a":
|
|
elementValue=1;
|
|
break;
|
|
case "b":
|
|
elementValue=100;
|
|
break;
|
|
case "c":
|
|
elementValue=1000000;
|
|
break;
|
|
case "d":
|
|
elementValue=10000;
|
|
break;
|
|
case "e":
|
|
elementValue=1000;
|
|
break;
|
|
case "f":
|
|
elementValue=10;
|
|
break;
|
|
case "g":
|
|
elementValue=10000000;
|
|
break;
|
|
case "o":
|
|
elementValue=100000;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
if(elem.classList.contains("activated")){
|
|
elem.classList.remove("activated");
|
|
segmentValue-=elementValue;
|
|
}else{
|
|
elem.classList.add("activated");
|
|
segmentValue+=elementValue;
|
|
}
|
|
displayResult();
|
|
}
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<div class="display">
|
|
<div id="a" onClick="clickSegment(this)" class="seg"></div>
|
|
<div id="f" onClick="clickSegment(this)" class="seg"></div>
|
|
<div id="b" onClick="clickSegment(this)" class="seg"></div>
|
|
<div id="g" onClick="clickSegment(this)" class="seg"></div>
|
|
<div id="e" onClick="clickSegment(this)" class="seg"></div>
|
|
<div id="c" onClick="clickSegment(this)" class="seg"></div>
|
|
<div id="d" onClick="clickSegment(this)" class="seg"></div>
|
|
<div id="o" onClick="clickSegment(this)" class="seg"></div>
|
|
</div>
|
|
<div id="info">
|
|
<h1>Seven-segment display value</h1>
|
|
<div id="description">Click any number of segments on the display on the left to get the corresponding values.</div>
|
|
<table id="result">
|
|
<tr>
|
|
<th>Type</th>
|
|
<th>Value</th>
|
|
<th>Padded</th>
|
|
</tr>
|
|
<tr>
|
|
<td>Binary</td>
|
|
<td id="bin"></td>
|
|
<td id="binPadded"></td>
|
|
</tr>
|
|
<tr>
|
|
<td>Hexadecimal</td>
|
|
<td id="hex"></td>
|
|
<td id="hexPadded"></td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
</body>
|
|
</html>
|