Friday, February 24, 2017

ESPBasic Series : Decimal-to-Binary conversion


   I was looking a while ago to implement some Decimal-to-Binary conversion subroutine to be used for easy visualisation of the Registry content. Been able to see the values directly binary can help a lot when developping a driver for a IC or any piece of related software:


1. Decimal-to-Binary subroutine:
 [decbin]
  i = 1
  r = 0
  binval = 0
  nr = decval
 Do
   r = nr % 2
   nr = int(nr/2)
   binval = binval + r*i
   i = i*10
 Loop while nr > 0
wait

  2. Test Program:
decval = 0
binval = 0
wprint "<br><br>Decimal value "

textbox decval
button " Convert ", [decbin]

wprint "<br><br> Binary value "
textbox binval
wprint "<br><br>"
button " Exit ", [TestExit] 
Wait

[TestExit]
 Looking forward to see your own ideas about!

Happy breadboarding,
TJ.

No comments:

Post a Comment