OVH Cloud OVH Cloud

comment convertir des entiers décimaux en entiers binaires ?

2 réponses
Avatar
Curtis Flam
Bonjour, la question est dans le titre.


Par exemple je voudrais à partir d'un entier décimal 4 obtenir la nombre
binaire 100.


Merci pour vos réponses.

2 réponses

Avatar
Olivier Miakinen

Par exemple je voudrais à partir d'un entier décimal 4 obtenir la nombre
binaire 100.


D'après la norme ECMAScript (15.7.4.2), monNombre.toString(2) devrait
faire l'affaire. Il est quand même précisé que le résultat est
« implementation-dependent », mais il m'étonnerait que ça ne marche
pas comme prévu.

Avatar
Dr J R Stockton
In fr.comp.lang.javascript message <45c10779$0$29456$
fr>, Wed, 31 Jan 2007 22:17:40, Curtis Flam posted:

Par exemple je voudrais à partir d'un entier décimal 4 obtenir la nombre
binaire 100.


<URL:http://www.merlyn.demon.co.uk/js-maths.htm#Base>

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.