18 lines
455 B
TypeScript
18 lines
455 B
TypeScript
import {Converter} from "./converter";
|
|
export class DecToBinConverter implements Converter {
|
|
getDisplayname():string {
|
|
return "Convert decimal to binary";
|
|
}
|
|
|
|
getId():string {
|
|
return "dectobin";
|
|
}
|
|
|
|
convert(input:string):string {
|
|
let n:number = parseInt(input, 10);
|
|
if (isNaN(n)) {
|
|
throw new Error("The input seems not to be a valid integer.");
|
|
}
|
|
return n.toString(2);
|
|
}
|
|
}
|