|
Booth Martin wrote:
> How would I do the same chore if the value to convert is a variable number
> from 0 to 255?
>
> What I want to do is to make a color value in hex from any base10 numeric
> color value. Color values are {red:blue:green} = {(0 to 255):(0 to
> 255):(0to255)} = {(00 to ff):(00 to ff):(00 to ff)}
>
> For example I'd like to convert '255:255:255' to 'ff:ff:ff'
A very simple (and fast) way is to define a 512 byte character string or
256 element 2-character string array and initialize it to contain
'000102030405060708090a0b0c0d0e0f..... etc. (alternatively '00' '01' '02'...)
Then use the decimal value (base10) as an index to do a substring or pick an
array element.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.