How to convert binary to hex in JavaScript

1 Answer

0 votes
let b = 11010;
let hex = parseInt(b, 2).toString(16).toUpperCase();
console.log(hex);
hex = hex.padStart(4, "0")
console.log(hex); 
 
b = 1001101011;
hex = parseInt(b, 2).toString(16).toUpperCase();
console.log(hex);
hex = hex.padStart(4, "0")
console.log(hex); 
 
    
   
   
/*
run:
    
1A
001A
26B
026B
    
*/

 



answered Dec 27, 2021 by avibootz
edited May 12, 2024 by avibootz
...