Skip to content

Instantly share code, notes, and snippets.

@alvesjnr
Created July 19, 2011 13:18
Show Gist options
  • Select an option

  • Save alvesjnr/1092278 to your computer and use it in GitHub Desktop.

Select an option

Save alvesjnr/1092278 to your computer and use it in GitHub Desktop.
Rgb marshall and unmarshell
-module(rgb).
-export([marshall/3, unmarshall/1]).
marshall(R,G,B) ->
if
R > 31 ->
throw({overlimit, R});
G > 63 ->
throw({overlimit, G});
B > 31 ->
throw({overlimit, B});
true -> true
end,
<< R:5, G:6, B:5 >>.
unmarshall(Binary) ->
<< R:5, G:6, B:5 >> = Binary,
{R,G,B}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment