GP32 Do I Need To Learn Hex?


Melville

Member
Joined
Apr 24, 2003
Messages
102
Hi, I'm trying to learn C++ at the moment (seems to make sense so far :)), but I'm having difficulty working out exactly what's going on in some of the example code for GP32 programs because they're full of Hex numbers.

I don't have the faintest clue how hex works (well, something about base-eight?), and being a lazy student, I would rather not have to learn unless it's really necessary.

So, is knowlege of hex essential / useful / just for showoffs when coding for GP32 in C++? If it's not important, could some kind person give me a clue what the hex in the code segment below means so I can get on with my life?

GpRectFill(NULL, &gpDraw[nflip], 0, 0, gpDraw[nflip].buf_w, gpDraw[nflip].buf_h, 0xff)

If hex is important, I'll start googling for tutorials (I hate maths :().

Thanks,
Melville

Apologies for all the superfluous commas - I blame poor teaching of grammar in schools.
 
Melville posted on Mar 2 2004 at 04:29 PM said:
Hi, I'm trying to learn C++ at the moment (seems to make sense so far :)), but I'm having difficulty working out exactly what's going on in some of the example code for GP32 programs because they're full of Hex numbers.

I don't have the faintest clue how hex works (well, something about base-eight?), and being a lazy student, I would rather not have to learn unless it's really necessary.

So, is knowlege of hex essential / useful / just for showoffs when coding for GP32 in C++? If it's not important, could some kind person give me a clue what the hex in the code segment below means so I can get on with my life?

GpRectFill(NULL, &gpDraw[nflip], 0, 0, gpDraw[nflip].buf_w, gpDraw[nflip].buf_h, 0xff)

If hex is important, I'll start googling for tutorials (I hate maths :().

Thanks,
Melville

Apologies for all the superfluous commas - I blame poor teaching of grammar in schools.
Basically, it's not base-eight but base-sixteen and easy to understand.
Think about 0xFF as FF (you can abandon that 0x, it only shows you're talking hex here). The general
rule of counting is 1-2-3-4-5-6-7-8-9-A-B-C-D-E-F.
F+1 would be 10, F+2 would be 11 and so on.
But, to calm you down, I did not need hex with C yet. the 0xFF can be substituted by normal decimal 255.
 
Last edited by a moderator:
Decimal (base 10) works like this (as I'm sure you'll remember from school) -

236 = 2*100 (or 2*10*10) + 3*10 + 6*1

Hex is base 16, and it works like this -

numbers go 1,2,3,4,5,6,7,8,9,a,b,c,d,e,f (so f=15)

the right digit is still 1, but now the next digit to the left is 16 (instead of 10). The next one to the left is 256 (16*16) instead of 100 etc.

so FF = 15*16 + 15*1 = 255

808 = 8*256 + 0*16 + 8*1 = 2056
 
Thanks :). That's nice and simple, so won't be a problem any more. I'll be left puzzling about why you'd want to use it now... maybe something to do with 16 = 2^4, which is used a lot in binary.

Or maybe it's something my poor biology-addled brain won't stand up to (I chose biology deliberately because it's the science with the least bizzarre algebra).

Either way, thanks very much for your helpful replies. My first bug-riddled, badly animated game for the GP32 edges ever closer! :)

Have fun,
Melville

EDIT (Having read woogal's post more closely): Yes, I see how base 16 would make the maths a little closer to the bite-size binary chunks that computer seem to love. If I'm wrong about this, don't worry - I'm quite happy in my delusion.

The only other facts I know about alternative base number systems:

The words eleven and twelve don't match the rest of the english base-ten counting system because they derive from the numbers used in a base 12 counting system in early britain and other areas (can't remember exactly where and when). The base-twelve counting system is apparenlty at least partly responsible for the weird multiples used in the Imperial measurement system, which we still retain 'cos we weren't conquered by that nice Mr. Napoleon, who was originally responsible for spreading (and inventing?) the metric system in the first place.

Much more useful to know:

In one of Douglas Adams' books, the Ultimate answer is 42, and the question in its distorted form is "what is six times seven?". I'm told this calculation is correct if you work it out in base thirteen.

I'm supposed to be writing an essay, but got bored of it. Can you tell? :)

Thanks again,
Melville
 
You half right about 42 in DNA's books - (as keeper of 42isms over at H2G2.com I can authoritatively answer that)...

IN base 10, 42 equals 6 multiplied by 7...

In the book/Radio series/TV Series/Tilm (yet to be) Arthur Dent and Ford Prefect draw letters from a Handmade Scrabble Set and get the question (to which the answer is 42) to be...

"What do you get if you multiply six by nine?"

The answer is of course 54 (base 10) which is 42 base 13!!

Hope that helps...
 
If you want to convert a hex number to decimal, or back you can use calc in Windows. Just make sure that it is in scientific mode.
 
Thanks for all your help guys :). Hex shouldn't be a problem now, and I can always use Charge's tip if I'm in doubt.

I'm off to find some more things I can't understand...

Thanks again,
Melville
 
Back
Top