Advertisement
Batchonline2

BIN2DEC in BAT

Oct 1st, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. ::::NUMERIQUE VERS DECIMAL
  2. ::::PAR SACHADEE
  3. ::::02-2013
  4.  
  5. @echo off
  6.  
  7. :::::DEFINIR LA VALEUR BINAIRE ICI:::::
  8.  
  9. set num-bin=100000100
  10.  
  11. cls
  12. set "puissance2=1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768"
  13.  
  14. setlocal enabledelayedexpansion
  15.  
  16. :::ON DECOMPOSE LA VALEUR NUMERIQUES PAR SUBSTITUTION
  17.  
  18. set "num-bin=%num-bin:1=1 %"
  19. set "num-bin=%num-bin:0=0 %"
  20. set "num-bin=%num-bin:~0,-1%"
  21.  
  22. echo.#%num-bin%#
  23.  
  24. :::ON INVERSE L ORDRE POUR AVOIR LA PLUS PETITE VALEUR EN PREMIER
  25.  
  26. for %%a in (%num-bin%) do (
  27. set "val=%%a"
  28. set "num-bin-inv=!val! !num-bin-inv!")
  29.  
  30. set "num-bin-inv=!num-bin-inv:~0,-1!"
  31.  
  32. :::ON BOUCLE SUR LA VALEUR INVERSEE SI ON A 1 ON ADDITIONE
  33. :::L'EQUIVALENCE DE LA LISTE DES PUISSANCES 2
  34.  
  35. set "compteur=1"
  36. set "val=0"
  37. for %%a in (!num-bin-inv!) do (
  38. if %%a==1 (
  39. set "compteur1=1"
  40. for %%b in (%puissance2%) do (if !compteur!==!compteur1! (set /a val=!val!+%%b)
  41. set /a compteur1+=1))
  42. set /a Compteur+=1)
  43.  
  44. echo.&echo.RESULTAT : !val!&echo.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement