Solved

Binary calculation

Posted on 2004-08-06
11
489 Views
Last Modified: 2010-04-05
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 :


http://www.arabsgate.com/edu/vb/images/uploads/26394_27164110ac4e48993.JPG
0
Comment
Question by:topkah
  • 3
  • 2
  • 2
  • +1
11 Comments
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 11734329
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.
0
 
LVL 11

Expert Comment

by:Jase-Coder
ID: 11734502
Have a look at TXSHexBinary

in the help files
0
 

Author Comment

by:topkah
ID: 11734599
thank you ...
and i wish if someone could write out this program.
0
 
LVL 11

Expert Comment

by:Jase-Coder
ID: 11735162
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
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Accepted Solution

by:
Molando earned 500 total points
ID: 11737066
//turns a number to a binary string
function numtobin(v : longint) : string;
var
 t,d : longint;
 firstbitfound : boolean;
begin
 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;
       end;
end;

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

example
edit1.Text := numtobin(  bintonum('1001010') + bintonum('010101') + 1 );
0
 
LVL 2

Expert Comment

by:Molando
ID: 11737153
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);
0
 
LVL 11

Expert Comment

by:Jase-Coder
ID: 11737985
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:

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=884&lngWId=7
0
 

Author Comment

by:topkah
ID: 11896085
Thank you . i solve it .
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Splash screen too shortlived 11 113
Thread safe  opinion 7 111
Working with hours 3 31
Dev Express grid collapse 2 34
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now