3.16 Type Conversions

There are a number of BIFs for type conversions.

Examples:

  1. 1> atom_to_list(hello).
  2. "hello"
  3. 2> list_to_atom("hello").
  4. hello
  5. 3> binary_to_list(<<"hello">>).
  6. "hello"
  7. 4> binary_to_list(<<104,101,108,108,111>>).
  8. "hello"
  9. 5> list_to_binary("hello").
  10. <<104,101,108,108,111>>
  11. 6> float_to_list(7.0).
  12. "7.00000000000000000000e+00"
  13. 7> list_to_float("7.000e+00").
  14. 7.0
  15. 8> integer_to_list(77).
  16. "77"
  17. 9> list_to_integer("77").
  18. 77
  19. 10> tuple_to_list({a,b,c}).
  20. [a,b,c]
  21. 11> list_to_tuple([a,b,c]).
  22. {a,b,c}
  23. 12> term_to_binary({a,b,c}).
  24. <<131,104,3,100,0,1,97,100,0,1,98,100,0,1,99>>
  25. 13> binary_to_term(<<131,104,3,100,0,1,97,100,0,1,98,100,0,1,99>>).
  26. {a,b,c}
  27. 14> binary_to_integer(<<"77">>).
  28. 77
  29. 15> integer_to_binary(77).
  30. <<"77">>
  31. 16> float_to_binary(7.0).
  32. <<"7.00000000000000000000e+00">>
  33. 17> binary_to_float(<<"7.000e+00">>).
  34. 7.0