Solved

# converting

Posted on 2012-04-06
387 Views
Hello

Can i be given an example of how to convert a string to decimal.

ie.

char ip;

ip = 10.10.10.10

which should give me the decimal equivilant after conversion 168430090

thank you
0
Question by:codey-06

LVL 32

Assisted Solution

phoffric earned 250 total points
ID: 37817280
168430090 = 0x0A0A0A0A
breaking that down into bytes: 0x0A 0x0A 0x0A 0x0A ~ 10 10 10 10
So, you need to parse out the 4 decimal values.
One way is to use strtok to do this.
http://www.cplusplus.com/reference/clibrary/cstring/strtok/
and then use atoi to convert to decimal
http://www.cplusplus.com/reference/clibrary/cstdlib/atoi/
Now that you have the 4 integer values, you need to start shifting (by 8 bits at a time, using << operator) and cumulative adding on each value to come up with the 32-bit integer. This value can then be displayed either as unsigned decimal or hex.
0

LVL 86

Accepted Solution

jkr earned 250 total points
ID: 37817650

``````char* ip;

ip = "10.10.10.10";

``````
0

## Featured Post

### Suggested Solutions

Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…