convert number

I need a procedure .... for convert a decimal number to binary number, for example

3=00000011 ........convertir(3)
16= 00010000 .......convertir(16)
chiroAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
rarigoConnect With a Mentor Commented:
This what you're looking for.

Function BinString( Number : Byte ) : String;
Var
   i : Integer;
begin
   Result := '';
   for i := 8 downto 0 do
   begin
      if ( Number AND ( 1 shl i )) <> 0 then
         result := result + '1'
      else
         result := result + '0';
   end;
end;


Isn't it?

Tchau
Reginaldo
0
 
chiroAuthor Commented:
Edited text of question.
0
 
sburckCommented:
function Int2binstring(value : cardinal) : string;
begin
     if value = 0 then result := '0' else
     begin
          result := '';
          while (value > 0) do
          begin
               if odd(value) then
                  result := '1' + result
               else
                   result := '0' + result;
               value := value shr 1;
          end
     end
end;
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
craig_capelCommented:
Tchau, yes thats better but a waste of using a function, a proc could have done the same thing......

Function BinString( Number : Byte ) : String;
 Var
  i : Integer;
  binstring2: string;
 begin
  binstring := '';
 for i := 8 downto 0 do
  begin
 if ( Number AND ( 1 shl i )) <> 0 then
   binstring2:=binstring2+'1'
  else
   binstring2 := binstring2 + '0';
  end;
 binstring:=binstring2;
end;

That Will Return it so then. stick an button and an edit box on... and type in this.

  s:=binstring(10);
  edit1.text:=s;

0
 
rarigoCommented:
Hi Craiq,

   You were so unhappy in your comment that you can't even tell it.

1 - Tchau is not my name. That's a greeting. Means bye-bye;

2 - You suggest ( i didn't know why ) using a procedure but used a function as well;

3 - Why do you need declare a new variable ( binstring2 ) when Delphi declare it automatically?  ( Return is a declared variable you can use the same way you did with binstring2 and you don't need to assign this way  -  binstring := binstring2 -  anymore ).

4 - Do you know you could do this:
    edit1.text:= BinString( AnyByte ) with that function I post here. Try it.



Tchau       ... Greeting
Reginaldo   ... my name



0
 
craig_capelCommented:
Nope, Reginaldo, for your fuction could have easily have been a Procedure......

UnHappy? Unhappy about what?., I tried your code and in order for me to get it to work, i had to either a) declair another var either inside the proc, or ext in the var section, i thought the way i addedd to your code made more sence, try it.


Craig C.  
0
 
sburckCommented:
Moot point, isn't it guys?  I beat you by a full minute! :)
0
 
chiroAuthor Commented:
thank
0
 
craig_capelCommented:
yep u did.......
0
 
sburckCommented:
But didn't get the points... :(
0
 
craig_capelCommented:
and nor did anyone else :)
0
 
craig_capelCommented:
oh wait some one did!!!
0
All Courses

From novice to tech pro — start learning today.