-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10.htm
More file actions
27 lines (23 loc) · 888 Bytes
/
10.htm
File metadata and controls
27 lines (23 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<!-- Write a JavaScript program to check whether a matrix is a diagonal matrix or not. In linear algebra, a diagonal matrix is a matrix in which the entries outside the main diagonal are all zero (the diagonal from the upper left to the lower right). -->
<!DOCTYPE html>
<html>
<head> </head>
<body>
<script>
let number = +prompt( "Enter a number" );
let binary;
if (isNaN(number)) {
alert ( "Please enter a valid number" );
}
else {
binary = number.toString(2);
let reversedBinary = "";
for (let i = binary.length-1; i >= 0; i--) {
reversedBinary += binary.charAt(i);
}
alert ( "Reversed binary number of the given number is " + reversedBinary );
alert( "Decimal representation of the reversed binary number is " + parseInt(reversedBinary, 2 ));
}
</script>
</body>
</html>