4
$\begingroup$

Given an RGB color {127, 255, 212} where scale is 0-255, VBA's RGB function find a long integer x such that

IntegerPart@{Mod[x,256],Mod[x/256,256],Mod[x/256^2,256]}

is equal to {127,255,212}. In this particular case the

x=13959039

How do i replicate this function in Mathematica?

$\endgroup$
4
$\begingroup$

You could use NumberCompose:

NumberCompose[{212,255,127},{256^2,256,1}]

13959039

$\endgroup$
3
$\begingroup$
fromRGB[{r_, g_, b_}] := r + 256*g + 65536*b
fromRGB[{127, 255, 212}]
(* 13959039 *)

or

fromRGB[rgb_List] := {1, 256, 65536}.rgb

(same result)

$\endgroup$
3
$\begingroup$
Reverse@IntegerDigits[13959039, 256]
FromDigits[Reverse@{127, 255, 212}, 256]

{127, 255, 212}

13959039

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.