Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 0.29 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. -module(rgb).
  2. -export([marshall/3, unmarshall/1]).
  3.  
  4. marshall(R,G,B) ->
  5.         if
  6.                 R > 31 ->
  7.                         throw({overlimit, R});
  8.                 G > 63 ->
  9.                         throw({overlimit, G});
  10.                 B > 31 ->
  11.                         throw({overlimit, B});
  12.                 true -> true
  13.         end,
  14.         << R:5, G:6, B:5 >>.
  15.  
  16. unmarshall(Binary) ->
  17.         << R:5, G:6, B:5 >> = Binary,
  18.         {R,G,B}.