Hello, I have been trying to figure out a way to convert a memory address, 0x200G69, or something similar, into an integer. I was hoping someone could help. I have had a few ideas like attempting to change the memory address into a character array then changing the characters into their ascii codes and adding them together, but that is not working. Any help would be great, thanks.
1 2 3 4 5
char temp[9] = &CDs[i]; //CDs is a CD**
int ascii = 0;
for(int i = 0; i < 9; i++)
ascii = ascii + temp[i];
cout << ascii << endl;
Let me add, I was wanting it in a comparable form of an int. I am trying to use something similar to this as a means to calculate weights between two nodes, vertices, of a graph to find the shortest distances.
I am trying to create a graph like storage system which contains the previous node's, vertex, memory address and the memory address of three other nodes. I am trying to use the memory address of the nodes to traverse this graph like structure to find the shortest route to the address of the piece of memory being sought out by the user.
Here, I think I have been making it seem more confusing. I am trying to use the memory addresses of what my pointers are pointing to, to maneuver through a system I have set up similar to a graph. What I am trying to do, is figure out a way to compute the current nodes weight via with its memory address by turning it into an int, then using this int to compare it to up's, down's, right's, and left's memory addresses to find the fastest path by this comparison to find the node the user wants.
template < class U >
class GraphNode
{
private:
GRAPH graphfactor;
GraphNode<U>* Up;
GraphNode<U>* Down;
GraphNode<U>* Right;
GraphNode<U>* Left;
//int weight;
U* vertice;
public:
GraphNode(U* vert);
~GraphNode();
bool End();
GraphNode<U>* getUp();
GraphNode<U>* getDown();
GraphNode<U>* getRight();
GraphNode<U>* getLeft();
U* getVertice();
int getWeight();
/* ^ ^ ^ ^
I'm trying to figure out how to convert the memory address
of this current node into an int to return to figure out if it
would be faster to use this node or not to find the location
of the item. Comment to int getWeight()
*/
void setGraphFactor(GRAPH factor);
GRAPH getGraphFactor();
void setVertice(U* vert);
void setUp(GraphNode<U>* edge);
void setDown(GraphNode<U>* edge);
void setRight(GraphNode<U>* edge);
void setLeft(GraphNode<U>* edge);
void insertUp();
void insertDown();
void insertRight();
void insertLeft();
void removeUp();
void removeDown();
void removeRight();
void removeLeft();
};