# String to Hexadecimal Conversion

**URL:** <https://forum.kirupa.com/t/string-to-hexadecimal-conversion/35218>\
**Category:** flash\
**Created:** [November 11, 2003, 7:06pm UTC](https://forum.kirupa.com/t/string-to-hexadecimal-conversion/35218 "2003-11-11T19:06:17Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jess](https://avatars.discourse-cdn.com/v4/letter/j/2bfe46/32.png) [@jess](https://forum.kirupa.com/u/jess)\
**Post date:** [November 11, 2003, 7:06pm UTC](https://forum.kirupa.com/t/string-to-hexadecimal-conversion/35218/1 "2003-11-11T19:06:17Z")

</div>

HI !

a quite simple problem in fact… …but can’t get rid of ! 😊

I parse a file from which I fetch String variables representing Hexadecimal values, in order to use them as RGB color codes.

How to convert these Strings into Hexadecimal values ?

For example, I load a variable with the value “0xFFFFFF” from a file. This varaible is a String. I want to use the value in a SetRGB function, but it can not handle String, and can’t do the conversion itself. So, how can make such a conversion ?

my\_color.setRGB(“0xRRGGBB”) does not work.  
I need my\_color.setRGB(0xRRGGBB).

Any idea ?  
:A+:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 11, 2003, 7:14pm UTC](https://forum.kirupa.com/t/string-to-hexadecimal-conversion/35218/2 "2003-11-11T19:14:58Z")

</div>

parseInt()

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 11, 2003, 9:18pm UTC](https://forum.kirupa.com/t/string-to-hexadecimal-conversion/35218/3 "2003-11-11T21:18:22Z")

</div>

hum…  
well, a s far as I knew, parseInt returns an integer value, not an hexadecimal. And functions like SetRGB requires an numeric hexadecimal value, don’t they ?

tell me wheter I’m wrong but,

if I wrote parseInt(“0x0000FF”, 16), I’ll get 255. WHat I need to get is 0x0000FF, as a numeric hexadecimal value.

:puzzle: I’m confused

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 11, 2003, 9:41pm UTC](https://forum.kirupa.com/t/string-to-hexadecimal-conversion/35218/4 "2003-11-11T21:41:24Z")

</div>

just tested this:  
[AS]  
myRGB = “0xffaaff”;  
parsedRGB = parseInt(myRGB);  
myColor = new Color(myMC);  
myColor.setRGB(parsedRGB);  
myMC.color  
[/AS]

and it works as far as I can see.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 11, 2003, 9:44pm UTC](https://forum.kirupa.com/t/string-to-hexadecimal-conversion/35218/5 "2003-11-11T21:44:02Z")

</div>

setRGB() can take a decimal integer or a hexidecimal value.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 11, 2003, 9:47pm UTC](https://forum.kirupa.com/t/string-to-hexadecimal-conversion/35218/6 "2003-11-11T21:47:55Z")

</div>

well, it seems the setRGB functions can handle integer values…

I should have made this test before asking my stupid questions ☹  
I was misguided by the flash documentation that always talk about hexadecimal values in its examples.

Anyway, thxx for your answer, cause parseInt does the job well, and now my work… works ! 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 11, 2003, 9:48pm UTC](https://forum.kirupa.com/t/string-to-hexadecimal-conversion/35218/7 "2003-11-11T21:48:55Z")

</div>

Flashmatazz , Rysolag : yep ! 🙂 I was writing my answer while you’were posting yours 😉

Again, thxx for your quick support 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 11, 2003, 9:52pm UTC](https://forum.kirupa.com/t/string-to-hexadecimal-conversion/35218/8 "2003-11-11T21:52:59Z")

</div>

No problem.

And:

> \*Originally posted by jess \*  
> \*\*and now my work… works ! 🙂 \*\*

LOL

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 11, 2003, 10:02pm UTC](https://forum.kirupa.com/t/string-to-hexadecimal-conversion/35218/9 "2003-11-11T22:02:01Z")

</div>

hexidecimal IS an integer. Its just a different format of writing it. Instead of using units of 10 per decimal place, it uses 16, hense the extra 6 letters used to write it. Even so, the value represented is no different than numbers which can be written in base 10.

0x000000 == 0  
0x0000FF == 255  
0xFFFFFF == 16777215

Its all the same.

Also, I was too lazy to type it before, but setRGB does allow string arguments. my\_color.setRGB(“0xRRGGBB”) should work fine.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 11, 2003, 10:14pm UTC](https://forum.kirupa.com/t/string-to-hexadecimal-conversion/35218/10 "2003-11-11T22:14:37Z")

</div>

yes, it does it fine.  
Thanxx for the lesson, lazy Senseï :ninja: … 😛
