Created
September 14, 2011 15:24
-
-
Save jeffreyolchovy/1216862 to your computer and use it in GitHub Desktop.
Convert a BSON ObjectId from binary to hex.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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