4

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?

user13892
  • 9,375
  • 1
  • 13
  • 41

3 Answers3

5

You could use NumberCompose:

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

13959039

Carl Woll
  • 130,679
  • 6
  • 243
  • 355
3
fromRGB[{r_, g_, b_}] := r + 256*g + 65536*b
fromRGB[{127, 255, 212}]
(* 13959039 *)

or

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

(same result)

John Doty
  • 13,712
  • 1
  • 22
  • 42
3
Reverse@IntegerDigits[13959039, 256]
FromDigits[Reverse@{127, 255, 212}, 256]

{127, 255, 212}

13959039

Henrik Schumacher
  • 106,770
  • 7
  • 179
  • 309