{"id":13509292,"url":"https://github.com/whatyouhide/convertat","last_synced_at":"2025-03-21T16:32:21.382Z","repository":{"id":22705052,"uuid":"26049084","full_name":"whatyouhide/convertat","owner":"whatyouhide","description":"An Elixir library for converting from and to arbitrary bases.","archived":false,"fork":false,"pushed_at":"2016-01-05T19:30:22.000Z","size":59,"stargazers_count":17,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-19T13:19:15.705Z","etag":null,"topics":["base-conversion","elixir"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/whatyouhide.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-11-01T11:38:19.000Z","updated_at":"2023-09-01T08:53:45.000Z","dependencies_parsed_at":"2022-08-21T00:00:37.978Z","dependency_job_id":null,"html_url":"https://github.com/whatyouhide/convertat","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whatyouhide%2Fconvertat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whatyouhide%2Fconvertat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whatyouhide%2Fconvertat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whatyouhide%2Fconvertat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/whatyouhide","download_url":"https://codeload.github.com/whatyouhide/convertat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221817074,"owners_count":16885455,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["base-conversion","elixir"],"created_at":"2024-08-01T02:01:05.780Z","updated_at":"2024-10-28T10:29:40.846Z","avatar_url":"https://github.com/whatyouhide.png","language":"Elixir","funding_links":[],"categories":["Text and Numbers"],"sub_categories":[],"readme":"# Convertat\n\n[![Build Status](https://travis-ci.org/whatyouhide/convertat.svg?branch=master)](https://travis-ci.org/whatyouhide/convertat)\n[![Coverage Status](https://img.shields.io/coveralls/whatyouhide/convertat.svg?style=flat)](https://coveralls.io/r/whatyouhide/convertat)\n[![Package](http://img.shields.io/hexpm/v/convertat.svg?style=flat)](https://hex.pm/packages/convertat)\n[![License](https://img.shields.io/hexpm/l/convertat.svg?style=flat)](LICENSE.txt)\n\nConvertat is a small Elixir library that provides functions for converting\nvalues **from** and **to** arbitrary bases.\n\n\n## Installation and docs\n\nTo use this library with Mix, just declare its dependency in the `mix.exs` file:\n\n``` elixir\ndefp deps do\n  [\n    # Using the hex package manager:\n    {:convertat, \"~\u003e 1.0\"},\n    # or grabbing the latest version (master branch) from GitHub:\n    {:convertat, github: \"whatyouhide/convertat\"},\n  ]\nend\n```\n\nThen run `mix deps.get`. The documentation for the current and the older\nversions of Convertat can be found on its [hex.pm\npage](https://hex.pm/packages/convertat).\n\n\n## Usage\n\nConvertat leverages on the power of the `|\u003e` operator in order to provide a\nclean syntax for converting values between bases. The only two functions that it\nexports are `Convertat.from_base/2` and `Convertat.to_base/3`.\n\nFor example, say we want to convert the binary value `\"11011\"` (27 in base 10)\nto its hex representation:\n\n``` elixir\niex\u003e \"10110\" |\u003e Convertat.from_base(2) |\u003e Convertat.to_base(16)\n\"1b\"\n```\n\nThat's pretty straightforward and, moreover, easily achievable using Elixir's\nstandard library (`String.to_integer/2` and `to_string/1`). In fact, when using\n*integers* as bases, you're limited to the standard `2..36` range.\n\nWhat about this:\n\n``` elixir\niex\u003e \"↑↓↑\" |\u003e Convertat.from_base([\"↓\", \"↑\"])\n5\n```\n\nWe just used a *binary* (it has two digits) base where the digits are the `\"↓\"`\nand `\"↑\"` strings.\n\nDigits in list bases are listed from the least significant one to the most\nsignificant one; in the above example, `↓` would be 0 in the binary base while\n`↑` would be 1.\n\nWe can also use lists as values (instead of strings); this allows for some cool\nmulticharacter-digits bases. Here's another binary base:\n\n``` elixir\niex\u003e [\"foo\", \"bar\"] |\u003e Convertat.from_base([\"bar\", \"foo\"])\n2\n```\n\nAs you can see, digits significance in list values is the opposite from bases:\nthe least significant digits are on the right, like they would be in written\nnumbers.\n\nWhile the `from_base/2` function converts a value in an arbitrary base to an\ninteger in base 10, the `to_base/3` function does the opposite:\n\n``` elixir\niex\u003e 20 |\u003e Convertat.to_base([\"a\", \"b\"])\n\"babaa\"\n```\n\nAs with `from_base`, bases can be integers (in the `2..36` range, just like with\nthe standard library) or lists of digits.\n\nBy default, a string representation of the converted number is returned. You\ncan also specify that you want a list:\n\n``` elixir\niex\u003e 16 |\u003e Convertat.to_base(16, as_list: true)\n[\"1\", \"0\"]\n```\n\nThis may seem useless, but think of the multichar-digits base from above:\n\n``` elixir\niex\u003e 2 |\u003e Convertat.to_base([\"bar\", \"foo\"])\n\"foobar\"\n```\n\nHow can you parse `\"foobar\"` back into a base 10 value with the same `[\"bar\",\n\"foo\"]` base?\n\n``` elixir\niex\u003e base = [\"bar\", \"foo\"]\n[\"bar\", \"foo\"]\niex\u003e val = 2 |\u003e Convertat.to_base(base, as_list: true)\n[\"foo\", \"bar\"]\niex\u003e val |\u003e Convertat.from_base(base)\n2\n```\n\nOne more thing: if you're converting between bases a lot of times, consider\n`import`ing the two functions for a uber-clean syntax:\n\n``` elixir\niex\u003e import Convertat, only: :functions\nnil\niex\u003e \"1011\" |\u003e from_base(2) |\u003e to_base(16)\n\"b\"\n```\n\n\n## Contributing\n\nIf you wish to contribute to this project, well, thanks! You know the deal:\n\n* fork the repository\n* make changes and **add/update tests**\n* make sure the tests pass by running `mix test`\n* commit changes\n* open a pull request\n\nFeel free to open an issue if you find something wrong with the library.\n\n\n## License\n\nMIT \u0026copy; 2014 Andrea Leopardi, see [the license file](LICENSE.txt)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhatyouhide%2Fconvertat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwhatyouhide%2Fconvertat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhatyouhide%2Fconvertat/lists"}