* [Caml-list] How do I convert 0x hexadecimal integers to decimal integers ?
@ 2003-03-27 17:20 Stalkern 2
2003-03-27 17:54 ` Stalkern 2
0 siblings, 1 reply; 5+ messages in thread
From: Stalkern 2 @ 2003-03-27 17:20 UTC (permalink / raw)
To: caml-list, ocaml_beginners
Hello to everybody
I'd need a function to turn hexadecimal integers like
0xb8f99c
( a Color in hexadecimal notation) to integer 3ples (e.g. `RGB
(184*256,249*256,156*256), always a color).
Shall I use Scanf functions and then some function converting hexadecimal
numbers to decimal? what would this function be?
T I A
Ernesto
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] How do I convert 0x hexadecimal integers to decimal integers ?
2003-03-27 17:20 [Caml-list] How do I convert 0x hexadecimal integers to decimal integers ? Stalkern 2
@ 2003-03-27 17:54 ` Stalkern 2
2003-03-27 17:58 ` Jun Furuse
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Stalkern 2 @ 2003-03-27 17:54 UTC (permalink / raw)
To: caml-list
Il Thursday 27 March 2003 18:20, Stalkern 2 ha scritto:
> Hello to everybody
> I'd need a function to turn hexadecimal integers like
> 0xb8f99c
> ( a Color in hexadecimal notation) to integer 3ples (e.g. `RGB
> (184*256,249*256,156*256), always a color).
>
> Shall I use Scanf functions and then some function converting hexadecimal
> numbers to decimal? what would this function be?
Well I see that I can also use String.sub but my problem would still be to
convert a hexadecimal integer like 0xb8f99c into a string like "0xb8f99c",
avoiding things like
# string_of_int 0xffffff;;
- : string = "16777215"
because in this case I don't know how to recognize the 3 integers that are
side by side... are they side by side because of a convention or is there a
way to convert "16777215" into the triple that I'm looking for?
T I A
Ernesto
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] How do I convert 0x hexadecimal integers to decimal integers ?
2003-03-27 17:54 ` Stalkern 2
@ 2003-03-27 17:58 ` Jun Furuse
2003-03-27 18:24 ` Brian Hurt
[not found] ` <002701c2f48a$555fa170$0201a8c0@mordor>
2 siblings, 0 replies; 5+ messages in thread
From: Jun Furuse @ 2003-03-27 17:58 UTC (permalink / raw)
To: stalkern2; +Cc: caml-list
> > I'd need a function to turn hexadecimal integers like
> > 0xb8f99c
> > ( a Color in hexadecimal notation) to integer 3ples (e.g. `RGB
> > (184*256,249*256,156*256), always a color).
> >
> > Shall I use Scanf functions and then some function converting hexadecimal
> > numbers to decimal? what would this function be?
let hex = 0xb8f99c in
let b = hex land 0xff in
let g = (hex lsr 8) land 0xff in
let r = (hex lsr 16) land 0xff in
`RGB (r lsl 8, g lsl 8, b, lsl 8)
BTW, if I prefere the following to get the conversion [0..255] => [0..65535]:
`RGB (r lsl 8 + r, g lsl 8 + g, b lsl 8 + b)
--
jun
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] How do I convert 0x hexadecimal integers to decimal integers ?
2003-03-27 17:54 ` Stalkern 2
2003-03-27 17:58 ` Jun Furuse
@ 2003-03-27 18:24 ` Brian Hurt
[not found] ` <002701c2f48a$555fa170$0201a8c0@mordor>
2 siblings, 0 replies; 5+ messages in thread
From: Brian Hurt @ 2003-03-27 18:24 UTC (permalink / raw)
To: Stalkern 2; +Cc: caml-list
Or maybe you want to do this:
let hexstring_of_int x = Printf.sprintf "%x" x ;;
Although once I got the integer into binary int form, I wouldn't convert
it back to a string untill I was printing the answer back. I would
instead do the shift/and code instead.
Brian
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <002701c2f48a$555fa170$0201a8c0@mordor>]
end of thread, other threads:[~2003-03-28 13:46 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-27 17:20 [Caml-list] How do I convert 0x hexadecimal integers to decimal integers ? Stalkern 2
2003-03-27 17:54 ` Stalkern 2
2003-03-27 17:58 ` Jun Furuse
2003-03-27 18:24 ` Brian Hurt
[not found] ` <002701c2f48a$555fa170$0201a8c0@mordor>
2003-03-27 18:42 ` Stalkern 2
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox