Skip to content

Instantly share code, notes, and snippets.

@jeffreyolchovy
Created September 14, 2011 15:24
Show Gist options
  • Save jeffreyolchovy/1216862 to your computer and use it in GitHub Desktop.
Save jeffreyolchovy/1216862 to your computer and use it in GitHub Desktop.
Convert a BSON ObjectId from binary to hex.
-module(objectid).
-author("[email protected]").
-export([binary_to_hex/1]).
extract_binary_data(BsonObjectId) ->
case BsonObjectId of {Binary} -> Binary; Binary -> Binary end.
binary_to_hex(BsonObjectId) ->
Binary = extract_binary_data(BsonObjectId),
list_to_binary(lists:flatten([io_lib:format("~2.16.0b", [X]) || <<X:8>> <= Binary])).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment