You are invited to Log in or Register a free Frihost Account!

# from integer to binary

Antoine_935
I'm looking for a table of translation : how to translate interger from 0 to 255 into binary code ==> 2 = 10 etc...
izcool
Might this help ? Not sure.

http://nickciske.com/tools/binary.php

- Mike.
Grimboy
Why do you need a table, it would be a very simple thing to do programaticaly and a function propebly already exists somewhere.
kv
use decbin() function. Simple. Isn't it?
Antoine_935
@izcool : not it doesn't help me at the moment, but maybe I'll need it on some day. thank you !

@Grimboy : at the moment I wrote this message, I did not know the algoritm. but now I've found it, so I'll do what you said

@kv : I would have used this function if it was in PHP, but it is in Python.
kv

http://www.daniweb.com/code/snippet285.html
XeononyX
Hello fellow coders! I stumbled upon this post and thought I would respond.. Translating Integer to Binary really isn't that tough by hand especially from 0 to 255

0 to 255 will always be 8 "bits"
now just imagine these bits have values, and these values double at each new bit. (These numbers are so familiar to computer users because computers go by sets similar to these)

128 , 64 , 32 , 16 , 8 , 4 , 2 , 1

check digits left to right 1: a) is your number greater than or equal to it (b) if so add a 1 to that bit or a 0 if lower. (c) then subtract the value of the digit from your number if you put a one there.

then repeat till done.

 Code: example : 169 1 ) ( 169>=128 ) YES b ) 1??????? c ) 169-128=41 2 ) ( 41 >=64  ) NO  b ) 10?????? c ) 41 3 ) ( 41 >=32  ) YES b ) 101????? c ) 41-32=9 4 ) ( 9  >=16  ) NO  b ) 1010???? c ) 9 5 ) ( 9  >=8   ) YES b ) 10101??? c ) 9-8=1 6 ) ( 1  >=4   ) NO  b ) 101010?? c ) 1 7 ) ( 1  >=2   ) NO  b ) 1010100? c ) 1 8 ) ( 1  >=1   ) YES b ) 10101001 c ) 1-1=0

there you go! 169 = 10101001
dandelion