2016-09-20 21:12:13 +02:00
|
|
|
import {Converter} from "./converter";
|
2017-03-14 15:42:11 +01:00
|
|
|
|
2016-09-20 21:12:13 +02:00
|
|
|
export class BinToDecConverter implements Converter {
|
2017-04-15 18:51:22 +02:00
|
|
|
getDisplayname(): string {
|
|
|
|
return "Convert binary to decimal";
|
|
|
|
}
|
2016-09-20 21:12:13 +02:00
|
|
|
|
2017-04-15 18:51:22 +02:00
|
|
|
getId(): string {
|
|
|
|
return "bintodec";
|
|
|
|
}
|
2016-09-20 21:12:13 +02:00
|
|
|
|
2017-04-15 18:51:22 +02:00
|
|
|
convert(input: string): string {
|
|
|
|
let n: number = parseInt(input, 2);
|
|
|
|
if (isNaN(n)) {
|
|
|
|
throw new Error("The input seems not to be a valid binary number.");
|
2016-09-20 21:12:13 +02:00
|
|
|
}
|
2017-04-15 18:51:22 +02:00
|
|
|
return n.toString(10);
|
|
|
|
}
|
2016-09-20 21:12:13 +02:00
|
|
|
}
|