Binary calculation

i want to make console application to calculate binary number for example :
my program will ask for number input like 1010001101 and save it in D.
then it will ask for another number and save it in (P) and this ( P) must be shorter than D at least with on character like 101000110 .
then new character( N ) = Number of  (D)  + number of (p) - 1 .

N= 10 + 6 -1 = 5

after that we will add Zeros after  (D) to become  101000110100000 then we divide it .

please see the picture here :
Who is Participating?
MolandoConnect With a Mentor Commented:
//turns a number to a binary string
function numtobin(v : longint) : string;
 t,d : longint;
 firstbitfound : boolean;
 t := v;
 d := 1073741824;
 result := '';
 firstbitfound := false;
 while d > 0 do
   if t >= d then begin
     result := result + '1';
     t := t - d;
     d := d div 2;
     firstbitfound := true;
     end else begin
       if firstbitfound then result := result + '0';
       d := d div 2;

//turns a binary string to a number
function bintonum(s : string) : longint;
  cnt : integer;
  t : longint;
  result := 0;
  t := 1;
  for cnt := length(s) downto 1 do begin
    if s[cnt] = '1' then result := result + t;
    t := t*2;

edit1.Text := numtobin(  bintonum('1001010') + bintonum('010101') + 1 );
Wim ten BrinkSelf-employed developerCommented:
I don't get your problem. But doesn't Delphi has a IntToBin and BinToInt function in the Math unit? Otherwise, it's not that hard to convert a binary to an integer anyway.
Have a look at TXSHexBinary

in the help files
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

topkahAuthor Commented:
thank you ...
and i wish if someone could write out this program.
Have a atrmpt at writing the program and where you get stuck post the problems and we'll help.
There is no point in one of us writing out the source code; you'll learn more by attempting it your self
if you want the final string a set length then:
  finalnumber : string;
  padsize : string;

   padsize := '0000000000' ; //add the number of zeros you want as the total length

   finalnumber := NumToBin( whatever you want here);
   finalnumber := copy(PadSize + finalnumber,length(PadSize + finalnumber)-length(padsize-1),padsize);
Hi topkah,
I just wanted to say I have created a program that converts ascii chars into binary strings. I have the code posted on planet-source-code and the link to the source is:
topkahAuthor Commented:
Thank you . i solve it .
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.