Hex to unsigned long?

Jumpem

Lifer
Sep 21, 2000
10,757
3
81
I have a simulation project I am doing.

One of the functions takes an unsigned long. I am given 2^15 or 00007FFF for it to be. How do I get that hex value into long?
 

shuan24

Platinum Member
Jul 17, 2003
2,558
0
0
converting hex value into long makes absolutely no sense.

edit: can you rephrase the question? you are comparing apples to oranges with that question.
 

Jumpem

Lifer
Sep 21, 2000
10,757
3
81
Originally posted by: shuan24
converting hex value into long makes absolutely no sense.

edit: can you rephrase the question? you are comparing apples to oranges with that question.


The professor gave us the maximum memory size for our simulator as 00007FFF. But the library function that implements memory takes a long.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Do you really mean an ASCII string of hex characters?

>> Nevermind, I'm a complete idiot. It's just 2^15 = 32,768.

In most languages no such conversion is needed unless it's ASCII.

unsigned long foo = 0x07fff ; // C++
 

Jumpem

Lifer
Sep 21, 2000
10,757
3
81
Originally posted by: DaveSimmons
Do you really mean an ASCII string of hex characters?

No this number is a constant that gets used at start up when creating the simulated "memory".
 

shuan24

Platinum Member
Jul 17, 2003
2,558
0
0
Originally posted by: Jumpem
Originally posted by: shuan24
converting hex value into long makes absolutely no sense.

edit: can you rephrase the question? you are comparing apples to oranges with that question.


The professor gave us the maximum memory size for our simulator as 00007FFF. But the library function that implements memory takes a long.


even so, i don't see what the problem is. The max memory is 32KB. Your function takes a long....not any different from taking a unsigned int.
 

Jumpem

Lifer
Sep 21, 2000
10,757
3
81
Originally posted by: shuan24
i guess you meant hex to decimal? or hex to binary?


Hex to decimal. It was simple, I just wasn't looking at it right.

He gave us the hex value to use on paper. But the code needed the decimal value.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Originally posted by: Jumpem
He gave us the hex value to use on paper. But the code needed the decimal value.
Not in most languages:

unsigned long foo = 0x07fff ; // C++
 

Jumpem

Lifer
Sep 21, 2000
10,757
3
81
Originally posted by: shuan24
ahh i remember the days of easy programming problems... :)


This project is going to be far from easy. We have to simulate a MIPS CPU.
 

Jumpem

Lifer
Sep 21, 2000
10,757
3
81
Originally posted by: shuan24
i guess for a comp arch class? good luck to you sir!

Yeah, it's comp arch. It's really kicking my butt. I transfered here from another school, and got transfer credit for the prereq course. Needless to say I'm not quite prepared for what I've gotten myself into.