   how to convert decimal to binar numbers ?
  i don''t wwant the code i just wanna know how. i know how to do it from binary to decimal but i tryied to do backward i can''t do it  can someone explain me ? thx in advance    Metal  Typhoon   
  You have to pick each bit independently. Use bitwise and (&) and left/right shifts (<< >>). You can write a loop that tests if bit 1 is set with &, then shifts 1 one bit to the left so that it becomes 2, uses 2 to test if bit 2 is set, and so on until you run out of bits.  ;  To convert 123 base 10 to base 2:123 mod 2 = 1123 / 2 = 6161 mod 2 = 161 / 2 = 3030 mod 2 = 030 / 2 = 1515 mod 2 = 115 / 2 = 77 mod 2 = 17 / 2 = 33 mod 2 = 13 / 2 = 11 mod 2 = 11 / 2 = 0Now read the modulii backwards (upwards): 1111011  ;quote:Original post by Melraidin  To convert 123 base 10 to base 2:123 mod 2 = 1123 / 2 = 6161 mod 2 = 161 / 2 = 3030 mod 2 = 030 / 2 = 1515 mod 2 = 115 / 2 = 77 mod 2 = 17 / 2 = 33 mod 2 = 13 / 2 = 11 mod 2 = 11 / 2 = 0Now read the modulii backwards (upwards): 1111011 OMG !!! i almost got it ! i divided by 2 but i didn''t know u had to saty with the modulus.. crap. but thx alot you helped me so much Metal  Typhoon    ;NumberValue = a0+a1*10+a2*100+a3*1000...aN*10^N= b0+b1*2+b2*4+b3*8...bN*2^NSo, if you have Number 99 ( decimal), you must div it firston Value div 128 (2^7) ... you got - 0. Then substract Value = 99-128*(Value div 128) = 99Then Value div 64  (2^6) -   you got - 1,Then substract Value = 99-64*(Value div 64) = 35Then Value div 32  (2^5) -   you got - 1,Then substract Value = 35-32*(Value div 32) = 3Then Value div 16  (2^4) -   you got - 0,Then substract Value = 3-3*(Value div 16) = 3....Then Value div 2  (2^1) -   you got - 1,Then substract Value = 3-3*(Value div 2) = 1Then Value div 1  (2^0) -   you got - 1,Then substract Value = 1-1*(Value div 1) = 0So you got answer: 01100011///////////////////////////////////Also, as known - computer work in binary, so we can domore simple:var Value:DWORD; // 32 bit - without sign S:string;    // string variable for answer...// we already have answer in computer memory (in binary)Value = DecimalValue;// We must only test bits on their values and store results. // Lets test all 32 bits on their value  for I:=0 to 31 do begin   // Test 0 bit on his value    if Value and 1 = 0 then S:=''0''+S    else S:=S+''1'';   // Move all bits right... example ( 0110000 shr 1 = 0011000)   Value:=Value shr 1; end;/// So we have anwer in variable S.. Print(''Answer = '',S);;  Or, of course if you want to do this in your head more quickly: start at the right hand side, and simply check whether the number is odd or even, if it''s odd write a 1, even, write a 0. Then divide by 2, throwing away the remainder. So:123:123 is odd, 1Divide 123 by 2, throw away remainder: 6161 is odd, 1Continue...Note: Same method as I posted previously, just easier to understand how to do it in your head....  ;  std::string toBinary ( int dec ){   std::string b;   for (int i = (sizeof (int)*8) - 1; i >=0 ; --i) if ((dec >> i) & 1)b+="1"; elseb+="0";   return b;}  