Lets say I have a telephone number which consists of 8 numbers - "29945987"
How to shorten it? Well.. one could convert it to different numeral system with base greater than 10.. The most popular would be hex numeral system with base-16. In that case the number would be "1C8F083" with only 7 symbols in it. My friend tried to convert it as an ASCII but didn`t do it mathematecally correctly :D so he has to rework it.
Ok, but - how to get it on a ... pixel? Well, what exactly is pixel? Working with different imagery software (starting with most popular and simplest Microsoft Paint and ending with complex Adobe Photoshop, Gimp, etc) users can "paint" or do whatever they are doing with custom made colors chosen from software color palette. The color "consists" of three "base channels" representing colors - red, green and blue each having a value from 0 to 255. So each pixel has these three values. Even better, there is some "pixel formats" with additional alpha channel for opacity.
What does it mean? It means, that in the one pixel there can be stored value, which doesn`t exceed 255^4 =4`228`250`625 - numerical information with 9 characters is safe to save in one pixel. Even better - in two pixels we can safely save information about 19 numbers or the maximum value stored in two pixels is 1.78781033478129 × 10^19 or 17878103347812900000.
The next thing is - how to encode and decode such an information?
Lets try to encode my number "29945987" in pixel step by step. Despite maybe there are another approaches how to do it, this one is mine:
The main rule is I have to split the number in 4 parts with values from 0 to 255.
The first part will be the alpha channel.
The value of alpha channel is calculated as the floor value from division of my number and the value 255^3
floor(29945987;255^3)=floor(29945987;16581375)=1 (alpha)
The second part will calculate the value for the red channel. For that we firstly need to calculate with remainder (first) of difference between given telephone number and 255^3.
mod(29945987;255^3)=mod(29945987;16581375)=13364612
Lets see is this number dividable with 255? Not really, there will be again some remainder (second) left. In such a case this second remainder can be any value from 0 to 255. Let us this value be the value for red channel
mod(13364612;255)=62
From here everything tangles, could be hard to follow.
What else we can do with the remainders we have? Previously we got second remainder with value 62. Subtracting it from first remainder, can this value be divided with 255^2?
13364612-62=13364550
In this case no, there is third remainder with value 34425.
mod(13364550;255^2)=mod(13364550;65025)=34425
Again, we are calculating the difference between second and third remainders getting the number which can be divided with 255^2 without remainder value=0.
13364550-34425=13330125
The division between calculated difference and 255^2 will be the value for third - green - channel. The calculated value will be lower than 255^3.
13330125/255^2=13330125/65025=205
And the last - blue - fourth channel value will be the division between third remainder and 255^1
34425/255 = 135
Does this all seems familiar? Well, this is my today`s empirical approach how to get values.
Actually - the similar approach could be done using base-x algorithm where x is any integer. In my case it should be 255.
And this is the RGBA color of my telephone number
And here it is in one small pixel: