1822735 Members
3851 Online
109644 Solutions
New Discussion юеВ

Re: How to Read Hex?

 
SOLVED
Go to solution
someone_4
Honored Contributor

How to Read Hex?

I am not a math major here.. But I was wondering if someone had a formula on how to read hex? I am talking about kernel parms like maxdsiz,maxtsiz,maxssiz and so on. I have been looking around and came up with 200mb in hex is 0xc8000000. Is this right? Is this number what I would put in maxdize? I am just wondering how hex works. And how you read it. And if I am coverting right.

Richard
20 REPLIES 20
harry d brown jr
Honored Contributor

Re: How to Read Hex?

#
echo 8000000 | awk '
{
hexstr="0123456789abcdef"
newnum=tolower($1)
slen = length(newnum)
decnum = 0
for (i=1; i < slen+1;i++)
{
tpos = index(hexstr,substr(newnum,i,1)) - 1
decnum = decnum + ( (16 ** (slen -i)) * tpos)
}
printf("%s is %d\n",newnum,decnum)
} '
#

live free or die
harry
Live Free or Die
harry d brown jr
Honored Contributor

Re: How to Read Hex?

Richard,

Of course, if you have a M$/puke machine, it's calculator has a HEX to DEC conversion.

And better yet,

/usr/dt/bin/dtcalcin/dtcalc

has a HEX option!



live free or die
harry
Live Free or Die
Patrick Wallek
Honored Contributor

Re: How to Read Hex?

For those kernel parms, you don't have to convert the value to hex. You can just enter the value in bytes into the field in SAM and it will be converted automagically.

200MB = 200 x 1024 x 1024 = 209715200 bytes
someone_4
Honored Contributor

Re: How to Read Hex?

So the Calculated Value: 67108864 is in bytes?
So right now I have 67108864 b = 65.536 MB ?

Richard

James R. Ferguson
Acclaimed Contributor

Re: How to Read Hex?

Hi Richard:

You can also do this at commandline:

# printf "%d\n" 0xfff

...which would return decimal 4095...and inversely:

# printf "%x\n" 4095

...which returns 0xfff

Regards!

...JRF...
harry d brown jr
Honored Contributor

Re: How to Read Hex?

8000000

looks like this:
8 * 16,777,216 (# * (16^6))
0 * _10,48,576 (# * (16^5))
0 * ____65,536 (# * (16^4))
0 * _____4,096 (# * (16^3))
0 * _______256 (# * (16^2))
0 * ________16 (# * (16^1))
0 * _________1 (# * (16^0)) -- remember 16^0 = 1
--------------
== 134,217,728


And yes, 0x4000000 = 67,108,864 bytes = 64MB (64 * 1024 * 1024)

l;ive free or die
harry
Live Free or Die
Eric Ladner
Trusted Contributor
Solution

Re: How to Read Hex?

Another quick way is to use bc and set ibase and obase respectively.

To convert from decimal to hex (we are setting the output base 16, leaving input at 10):

$ bc -l
obase=16
256*1024*1024
10000000
255
FF
quit

To convert hex numbers to decimal (we are setting the input base to base 16, leaving the output base at 10)

$ bc -l
ibase=16
FF
255
40000000
1073741824
FFFF
65535
quit

Note that the hex numbers entered MUST be in upper case to work, otherwise you will get syntax errors.

someone_4
Honored Contributor

Re: How to Read Hex?

printf "%d\n" 0xc8000000
printf: Error converting 0xc8000000
2147483647

printf "%x\n" 200 c8

printf "%d\n" 0xc8 200

what about the last 000000? Do they not count?

Richard
Patrick Wallek
Honored Contributor

Re: How to Read Hex?

Richard,

I suspect you are in the k-shell when doing the printf and getting the error. Switch to the posix shell (/usr/bin/sh or /sbin/sh) and you won't have a problem.

And YES, the 0's at the end DEFINITELY DO MATTER. Chopping the 0's off of the end of the hex # would be about like chopping the last 5 zeros off of 1000000. 10 != 1000000 and 0xc8 != 0xc8000000

0xc8 = 200
0xc8000000=2,147,483,647 = 2GB
Josh_13
Super Advisor

Re: How to Read Hex?

most simplistic thing i can think of is to use javascript.

####.toString(10)


where #### is the hex number

here's a quickly written html page to use. double check that i have it right before using it. you might have to alert toString that the number is NOT base 10.








<script language=javascript>
function convert(){
var hexnum=(document.todec.hex.value);
document.todec.dec.value=(hex.toString(10));
};}
</script>

Josh_13
Super Advisor

Re: How to Read Hex?

define irony:

taking a minute to write what i wrote before, then coming across this thread, http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x077350011d20d6118ff40090279cd0f9,00.html when searching for the success thread to add my latest one to that.
(n/a for this. it was dumb luck that i found the thread.)
Eric Ladner
Trusted Contributor

Re: How to Read Hex?

The printf fails in ksh because the number is larger than the interal representation of %d.

Come on guys! Use the 'bc' command.. it doesn't get any simpler than that.

bc successfully printed this out:

$ bc
ibase=16
C00000000000000000000000000000000000
16725558898897967356151788704486271129485312

That's a rather large number. It'll go much larger, but then it'd wrap and look nasty..

someone_4
Honored Contributor

Re: How to Read Hex?

I understand !! whoo hooo !!!
hex is 16 based !

so here we go ..

0x4000000 = 67,108,864 bytes = 64MB (64 * 1024 * 1024)

If I want 200MB

200MB=(200*1024*1024)= 209715200 bytes = C8000000


c8000000 is not = 2,147,483,647 = or 2GB

the hex covert says
2,147,483,647 B = 7FFFFFFF in hex


and

c8000000 = 3355443200 bytes = 3200 mb = 3 GB

It looks like the hex calc and bc are always form bytes to hex .right?


So using the hex coverter

0x4000000 = 64 MB
and I am wanting to bump it up to 200MB
so I would use
0xc8000000
or more simple for 128MB
0x8000000

Here it all is using the bc.

#bc -l
ibase=16
C8000000
3355443200
8000000
134217728
C8000000
3355443200
4000000
67108864
8000000
134217728


#bc -l
obase
10
obase=16
256*1024*1024
10000000
2147183647
7FFB6C1F
67108846
3FFFFEE
67108864846
FA000034E
67108864
4000000
3355443200
C8000000
134217728
8000000
quit
Patrick Wallek
Honored Contributor

Re: How to Read Hex?

You are getting a bit 0 happy when typing Richard.

200 MB = c800000 (only 5 zero's)

2GB = 80000000 (7 zero's)

3.125 GB = c8000000 (6 zero's)

Make VERY sure you type the correct # of zero's. They are VERY significant. (The difference between hundreds, thousands, millions, billions)
someone_4
Honored Contributor

Re: How to Read Hex?

Ha ha ..
I just caught that my self and was doing that math ..

(NET-lupus) /# bc -l
ibase=16
C8000000
3355443200
7FFFFFFF
2147483647
quit
(NET-lupus) /# bc -l
obase=16
256*1024*1024
10000000
209715200
C800000
3355443200
C8000000

You are very right though =)
I have to watch that ..

Richard
harry d brown jr
Honored Contributor

Re: How to Read Hex?

Richard,

c8000000 is not = 2,147,483,647 = or 2GB

is correct, because C8000000 is 200MB (200 * 1024 * 1024), whereas 2GB is (2 * 1024 * 1024 * 1024) = 2147483648 = 0x80000000.

and 256MB is (256 * 1024 * 1024) = 268435456 = 0x10000000


live free or die
harry
Live Free or Die
someone_4
Honored Contributor

Re: How to Read Hex?

Hex is just too much fun =)
Would anyone happened to know how they get theese numbers from hex to decimal and back. Is there an acutal math formula?

Richard
Patrick Wallek
Honored Contributor

Re: How to Read Hex?

Just take Harr's response and expand on it:


# * (16^16)= ???
# * (16^15)= ???
# * (16^14)= ???
# * (16^13)= ???
# * (16^12)= ???
# * (16^11)= ???
# * (16^10)= ???
# * (16^9)= ???
# * (16^8)= ???
# * (16^7)= ???
# * (16^6)= ???
# * (16^5)= ???
# * (16^4)= ???
# * (16^3)= ???
# * (16^2)= ???
# * (16^1)= ???
# * (16^0)= ??? - remember 16^0 = 1
and then add them all together to get your value. There really is no other magic formula.

In hex the "number" range from 0-9 then a-f. So if you were counting it would be:
0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,10,11,12
where a=10, b=11, c=12, d=13, e=14, f=15.

So lets convert a hex to decimal:

fba563

f = 15 = 15 * (16^5) = 15 * 1048576 = 15728640
b = 11 = 11 * (16^4) = 11 * 65546 = 720,896
a = 10 = 10 * (16^3) = 10 * 4096 = 40960
5 = 5 * (16^2) = 5 * 256 = 1280
6 = 6 * (16^1) = 6 * 16 = 96
3 = 3 * (16^0) = 3 * 1 = 3

Now add up 15,728,640 + 720,896 + 40,960 + 1,280 + 96 + 3 = 16,491,875

You basically start with the last digit and multiply it by 16^0 (16 to the power of 0) and work your way back to the left incrementing the power by 1 each time (16^1, 16^2, etc.)

Understand?
Eric Ladner
Trusted Contributor

Re: How to Read Hex?

Just a personal view..

I'd use 256MB for maxdsiz instead of an 'odd' number (that's 10000000 in hex, or a 1 with 7 zeros).

Call me funny, but I like to keep the kernel params nice round numbers, especially when dealing with memory.

Also, there's nothgin wrong (that I can tell) of setting maxdsiz to the amount of physical memory on the box.
Josh_13
Super Advisor

Re: How to Read Hex?

lol. ironically enough, the code i wrote was bsed on what i remeberd of the hex converter i had to write for hte multimedia class i took last semester (basically an advanced web design focusing on asp and php with an overview of javascript). i know i have a working hex converter if you'd like me to post it, let me know.