Skip to content

Commit ad001c4

Browse files
authored
Merge pull request #73 from AlexDvorak/master
added DecimalToHex
2 parents 2450f24 + 8a356cd commit ad001c4

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

Conversions/DecimalToHex.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function intToHex(num){
2+
switch(num){
3+
case 10: return "A";
4+
case 11: return "B";
5+
case 12: return "C";
6+
case 13: return "D";
7+
case 14: return "E";
8+
case 15: return "F";
9+
}
10+
return num;
11+
}
12+
13+
function decimalToHex(num){
14+
let hex_out = [];
15+
while(num > 15) {
16+
hex_out.push(intToHex(num%16));
17+
num = Math.floor(num / 16);
18+
}
19+
return intToHex(num) + hex_out.join("");
20+
}
21+
22+
// test cases
23+
console.log(decimalToHex(999098) === "F3EBA");
24+
console.log(decimalToHex(123) === "7B");

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,13 @@ In cryptography, a **transposition cipher** is a method of encryption by which t
140140
Mathematically a bijective function is used on the characters' positions to encrypt and an inverse function to decrypt.
141141
###### Source: [Wikipedia](https://en.wikipedia.org/wiki/Transposition_cipher)
142142

143+
----------------------------------------------------------------------------------------------------------------------
144+
145+
## Checksums
146+
147+
### Luhn's
148+
The Luhn algorithm or Luhn formula, also known as the "modulus 10" or "mod 10" algorithm, is a simple checksum formula used to validate a variety of identification numbers, such as credit card numbers, IMEI numbers, National Provider Identifier numbers in the United States, Canadian Social Insurance Numbers, Israel ID Numbers and Greek Social Security Numbers. It was created by IBM scientist Hans Peter Luhn and described in U.S. Patent No. 2,950,048, filed on January 6, 1954, and granted on August 23, 1960.
149+
###### Source: [Wikipedia](https://en.wikipedia.org/wiki/Transposition_cipher)
143150
[bubble-toptal]: https://www.toptal.com/developers/sorting-algorithms/bubble-sort
144151
[bubble-wiki]: https://en.wikipedia.org/wiki/Bubble_sort
145152
[bubble-image]: https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Bubblesort-edited-color.svg/220px-Bubblesort-edited-color.svg.png "Bubble Sort"

0 commit comments

Comments
 (0)