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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
rarigoCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.