Jump to content

Decimal to Hex text string ?


Recommended Posts

How do I convert a variable, that has a Decimal value between 0 and 65535 into a text string that looks like this...

If Decimal = 0

Hex should be = #000000000000

If Decimal is = 1

Hex should be = #000100010001

If Decimal is = 65535

Hex should be = #FFFFFFFFFFFF

As you see, the string should contain the Decimal 3 times in a row, with the hash sign infront.

I need it to feed an Imagemagick command that looks like this..

$compare = $img.Compare("bitmap1.bmp", _
                "bitmap2.bmp", _
                "-depth", "16", _
                "-highlight-color", "#123412341234", _
        "bitmapresult.pgm" )

I wanna feed the "#123412341234" part with a variable, but dunno how to convert the decimal variable into such a text string.

Anyone ?

Edited by Werty

Some guy's script + some other guy's script = my script!

Link to comment
Share on other sites

Its for Imagemagick? Would be interesting to see this :blink:...

$dec = 65535

$compare = $img.Compare("bitmap1.bmp", _
        "bitmap2.bmp", _
        "-depth", "16", _
        "-highlight-color", _ColorDecToHex4($dec),
_ "bitmapresult.pgm")

Func _ColorDecToHex4($dec)
    $Hex = hex($dec,4)
    Return "#" & $Hex & $Hex & $Hex
EndFunc
Link to comment
Share on other sites

lol, was it that simple, guess I should have read up on Hex() before asking, only remember it from my old ZX Basic days, where there was no option for defining how many chars. ;)

I'm making height maps and was limited to 8bit 256 grays...

post-58319-12795519104074_thumb.png

But now I got 65536 grays to work with. :P

Thanks for your help. :blink:

Some guy's script + some other guy's script = my script!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...