![]() |
|
#1
|
|||
|
|||
Math problem, I am stumped.Ok, I am not a programmer and only write small EXE programs to take care of easy tasks. I threw a program together real quick to do some simple math functions to an IP address. The point of this is to take the IP and convert it to whats called a DWORD. I won't go in depth of why I am doing this, but I am having trouble. The math doesnt seem to be doing what its supposed to. I am coming up with some crazy answers and I am not sure why. Someone please help me out.
Heres what it should do... First Octet * 16,777,216 Second Octet * 65,536 Third Octet * 11,010,048 Forth Octet * 1 Everything compiles fine and it works, just the wrong ending value. Just as a reference 192.168.1.1 should equal 3,232,235,777. Thanks in advance. CPP / C++ / C Code:
Last edited by LuciWiz : 04-Jan-2007 at 22:25.
Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
|
|||
|
#2
|
|||
|
|||
Re: Math problem, I am stumped.Quote:
CPP / C++ / C Code:
You need to, CPP / C++ / C Code:
CPP / C++ / C Code:
|
|
#3
|
|||
|
|||
Re: Math problem, I am stumped.I had them set up in variables, but right before I posted it I took them out, even with them in it still didn't work. I just noticed the second option you mentioned but that gave me the same wrong result. I don't get why this is not working, its such a simple math equation.
|
|
#4
|
|||
|
|||
Re: Math problem, I am stumped. |
|
#5
|
|||
|
|||
Re: Math problem, I am stumped.Thanks that helped in some way. Now I just know that its not possible. Ugh.
|
|
#6
|
|||
|
|||
Re: Math problem, I am stumped.Quote:
You are trying to store four octets in a variable, so you need a variable whose length is 32 bits (four chars). Most compilers these days have 32-bit ints. If yours has 16-bit ints, then you should be able to use long ints. Try this: CPP / C++ / C Code:
If is says that the size an unsigned int is equal to 4, then you can use unsigned ints. If it says that the size of an unsigned long is equal to 4, then you can use unsigned long ints. Whichever one you try, if you still have trouble then: 1. Post the code. The exact code that you are using. Paste it into your post. It really doesn't make sense for you to run one file but post another and expect someone to help. Your first post would not compile on any of the several compilers to which I have access. 2. Tell us what compiler you are using and what operating system. Post any compiler messages that you got. Paste them directly into your post. Don't paraphrase. 3. Show the exact input and output (just post the text into your post). Simply saying, "It doesn't work," doesn't give us much to work with when we are trying to help you understand how to go forward. And that's the point, right? Regards, Dave |
|
#7
|
|||
|
|||
Re: Math problem, I am stumped.had that error once
took long to figure out but then i realised it was easier than i thought. |
|
#8
|
|||
|
|||
Re: Math problem, I am stumped.Quote:
|
Recent GIDBlog
Ph.D. progress by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Math problem: Total Noob | Targsmom | C Programming Language | 3 | 20-Oct-2006 05:05 |
| Buffer problem with CD-RWriter | KieranC | Computer Software Forum - Windows | 2 | 07-Jan-2006 01:45 |
| Graphic problem in Unreal Tournament 2004 | zerox | Computer Software Forum - Games | 10 | 09-Oct-2005 12:31 |
| Runtime Problem involving "printf" in C Program | supamakia | C Programming Language | 2 | 09-Oct-2005 10:09 |
| a significant problem after installing Xp | mohammad | Computer Software Forum - Windows | 10 | 09-Aug-2005 07:03 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The