Question d’entretien chez Ooyala

Write a method which transforms an integer into a binary number, no libraries using (on a whiteboard).

Réponses aux questions d'entretien

Utilisateur anonyme

20 juil. 2012

def num_bits(n) nbits = 0 while n > 1 n /= 2 nbits += 1 end nbits end def int2bin(n) nbits = x = num_bits(n) total = 0 bin = "" for i in (0..nbits) addon = (2 ** x) if((total + addon) <= n) bin += "1" total += addon else bin += "0" end x -= 1 end bin end

Utilisateur anonyme

20 sept. 2012

http://stackoverflow.com/questions/8151435/integer-to-binary-array

Utilisateur anonyme

30 mars 2014

public static String toBinaryString (int n){ StringBuffer sb = new StringBuffer (); while ( n > 0 ){ int bit = n%2; sb.insert(0, bit); n=n/2; } return sb.toString(); } public static void main(String[] args) { System.out.println (toBinaryString(25)); }

Utilisateur anonyme

30 déc. 2010

Perfect syntax was not required