Jump to content

Looking for help in Free Pascal

Hey,

So, we are currently studying programming in Free Pascal and I got this task to complete within this day, i can't find any solution and I am not that good at this, so I am asking for someone to help. 

 

Task :

I have to make program in Free Pascal (keep in mind that it's Pascal) :D that allows you to type in your IP adress and it converts it from decimal numbering system to binary numbering system. Also it has to do something with operations div  and mod.

 

Thanks,

And sorry if there are any mistakes, I'm not speaking english in general.

Link to comment
Share on other sites

Link to post
Share on other sites

Right, so what problems do you have? Where to start? How to convert from decimal to binary?

Molex to SATA, lose all your data

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, sirtoby said:

Right, so what problems do you have? Where to start? How to convert from decimal to binary?

I know how to convert from decimal to binary, the problem is that i have to convert the IP address and it consist mostly of 4 parts like 192.xxx.x.x, which are seperate and i can't find any way to do that. 

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, unknowngeek222 said:

I know how to convert from decimal to binary, the problem is that i have to convert the IP address and it consist mostly of 4 parts like 192.xxx.x.x, which are seperate and i can't find any way to do that. 

Did you already learn about arrays?

Molex to SATA, lose all your data

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, sirtoby said:

Did you already learn about arrays?

Yes, I did.

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, unknowngeek222 said:

Yes, I did.

Al right, so here's what I'd do: You have an IP-address; 4 blocks, each of which consists of a number between 0 and 255. Instead of trying to handle them all together, split them up. For example, you could put them in an array. You could also assign a variable to each of the four numbers. 

//Example
//IP is 192.168.189.23
// Array
[192 168 189 23]
//Variables
Number1 = 192
Number2 = 168
Number3 = 189
Number4 = 23

Use whatever you are most comfortable with using. I don't know how you're supposed to present this, but in the most basic form it'd look something like this (Syntax is not correct)

//IP address is 1.2.3.4

Var1 = 1		Bin1
Var2 = 2		Bin2
Var3 = 3		Bin3
Var4 = 4		Bin4
  
//convert Var1-4 into binary, maybe additional variables are neccessary to store the binary numbers
  
Print out ("You converted " Var1 "." Var2 "." Var3 "." Var4 "into" Bin1 "." Bin2 "." Bin3 "." Bin4)

 

Molex to SATA, lose all your data

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

5 minutes ago, sirtoby said:

Al right, so here's what I'd do: You have an IP-address; 4 blocks, each of which consists of a number between 0 and 255. Instead of trying to handle them all together, split them up. For example, you could put them in an array. You could also assign a variable to each of the four numbers. 


//Example
//IP is 192.168.189.23
// Array
[192 168 189 23]
//Variables
Number1 = 192
Number2 = 168
Number3 = 189
Number4 = 23

Use whatever you are most comfortable with using. I don't know how you're supposed to present this, but in the most basic form it'd look something like this (Syntax is not correct)


//IP address is 1.2.3.4

Var1 = 1		Bin1
Var2 = 2		Bin2
Var3 = 3		Bin3
Var4 = 4		Bin4
  
//convert Var1-4 into binary, maybe additional variables are neccessary to store the binary numbers
  
Print out ("You converted " Var1 "." Var2 "." Var3 "." Var4 "into" Bin1 "." Bin2 "." Bin3 "." Bin4)

 

Thanks, ill try to understand this. But how do I do the thing with getting my IP in?

like

Writeln('Type in your IP');

readln(...) what do I do with the readln?

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, unknowngeek222 said:

Thanks, ill try to understand this. But how do I do the thing with getting my IP in?

like

Writeln('Type in your IP');

readln(...) what do I do with the readln?

That was what I was referring to. I don't know if you're supposed to deliver a complete program, or if it is enough if you just put the numbers into the code and let it run  in free pascal. 

I haven't dealt with Pascal so far, but read/readln seems to be the right command. Maybe this helps you on how to use it https://en.wikibooks.org/wiki/Pascal_Programming/Input_and_Output

Molex to SATA, lose all your data

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

19 minutes ago, sirtoby said:

That was what I was referring to. I don't know if you're supposed to deliver a complete program, or if it is enough if you just put the numbers into the code and let it run  in free pascal. 

I haven't dealt with Pascal so far, but read/readln seems to be the right command. Maybe this helps you on how to use it https://en.wikibooks.org/wiki/Pascal_Programming/Input_and_Output

Okay, thank you! :)

Link to comment
Share on other sites

Link to post
Share on other sites

21 minutes ago, unknowngeek222 said:

Thanks, ill try to understand this. But how do I do the thing with getting my IP in?

like

Writeln('Type in your IP');

readln(...) what do I do with the readln?

Quote

procedure ReadLn(

  var F: Text;

  Args: Arguments

);

procedure ReadLn(

  Args: Arguments

);

 

readln() reads a line from a text file/stdin. It's very similar to read(), both take as a first parameter the input file, and If none is specified, then it reads from stdin. The second parameter is a variable which you read into, and it must be of type Char, Integer, Real, String or PChar.

http://www.freepascal.org/docs-html/rtl/system/read.html

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, Nineshadow said:

readln() reads a line from a text file/stdin. It's very similar to read(), both take as a first parameter the input file, and If none is specified, then it reads from stdin. The second parameter is a variable which you read into, and it must be of type Char, Integer, Real, String or PChar.

http://www.freepascal.org/docs-html/rtl/system/read.html

I know how to use readln, i just wanted to know how do I type my IP so i can calculate other things later.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×