GitHub 6248★

Convert decimal to binary recursively

JavaScript version

const decToBi = (num) => (num === 0 ? 0 : (num % 2) + 10 * decToBi(~~(num / 2)));

TypeScript version

const decToBi = (num: number): number => (num === 0 ? 0 : (num % 2) + 10 * decToBi(~~(num / 2)));

Examples

decToBi(10); //1010
Follow me on and to get more useful contents.