{"action":"created","issue":{"url":"https://api.github.com/repos/alekseynemiro/Nemiro.Convertion/issues/1","labels_url":"https://api.github.com/repos/alekseynemiro/Nemiro.Convertion/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/alekseynemiro/Nemiro.Convertion/issues/1/comments","events_url":"https://api.github.com/repos/alekseynemiro/Nemiro.Convertion/issues/1/events","html_url":"https://github.com/alekseynemiro/Nemiro.Convertion/issues/1","id":74684040,"number":1,"title":"Не правильно переводит обратно","user":{"login":"alexeygritsenko","id":10233486,"avatar_url":"https://avatars.githubusercontent.com/u/10233486?v=3","gravatar_id":"","url":"https://api.github.com/users/alexeygritsenko","html_url":"https://github.com/alexeygritsenko","followers_url":"https://api.github.com/users/alexeygritsenko/followers","following_url":"https://api.github.com/users/alexeygritsenko/following{/other_user}","gists_url":"https://api.github.com/users/alexeygritsenko/gists{/gist_id}","starred_url":"https://api.github.com/users/alexeygritsenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexeygritsenko/subscriptions","organizations_url":"https://api.github.com/users/alexeygritsenko/orgs","repos_url":"https://api.github.com/users/alexeygritsenko/repos","events_url":"https://api.github.com/users/alexeygritsenko/events{/privacy}","received_events_url":"https://api.github.com/users/alexeygritsenko/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-05-09T14:22:45Z","updated_at":"2015-05-10T15:51:09Z","closed_at":null,"body":"Добрый день, прежде всего моя благодарность за столь полезную библиотеку!\r\nОднако, столкнулся с проблемой, при переводе обратно только что полученного значения системой счисления оно отличается от первоначального((((\r\nТестовый код:\r\n\r\n            string DIC = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\r\n            long res1 = Convertion.FromBaseX(\"ABC\", DIC);\r\n            string res2 = Convertion.ToBaseX(res1, DIC);\r\n\r\n            if (\"ABC\" != res2) \r\n                Console.WriteLine(\"Не верно перевел обратно!\");"},"comment":{"url":"https://api.github.com/repos/alekseynemiro/Nemiro.Convertion/issues/comments/100658676","html_url":"https://github.com/alekseynemiro/Nemiro.Convertion/issues/1#issuecomment-100658676","issue_url":"https://api.github.com/repos/alekseynemiro/Nemiro.Convertion/issues/1","id":100658676,"user":{"login":"alekseynemiro","id":6204692,"avatar_url":"https://avatars.githubusercontent.com/u/6204692?v=3","gravatar_id":"","url":"https://api.github.com/users/alekseynemiro","html_url":"https://github.com/alekseynemiro","followers_url":"https://api.github.com/users/alekseynemiro/followers","following_url":"https://api.github.com/users/alekseynemiro/following{/other_user}","gists_url":"https://api.github.com/users/alekseynemiro/gists{/gist_id}","starred_url":"https://api.github.com/users/alekseynemiro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alekseynemiro/subscriptions","organizations_url":"https://api.github.com/users/alekseynemiro/orgs","repos_url":"https://api.github.com/users/alekseynemiro/repos","events_url":"https://api.github.com/users/alekseynemiro/events{/privacy}","received_events_url":"https://api.github.com/users/alekseynemiro/received_events","type":"User","site_admin":false},"created_at":"2015-05-10T15:51:09Z","updated_at":"2015-05-10T15:51:09Z","body":"Проще всего убирать нули, при помощи метода **TrimStart**:\r\n```C#\r\nstring DIC = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\r\nstring num = \"ABC\";\r\nvar res11 = Convertion.FromBaseX(num.TrimStart('A'), DIC);\r\nvar res22 = Convertion.ToBaseX(res11, DIC);\r\nConsole.WriteLine(\"{0} = {1}\", res11, res22);\r\n```\r\n[Посмотреть, как это работает](https://dotnetfiddle.net/aDZjBA).\r\n\r\nИли можно переделать функцию **FromBaseX**, чтобы она возвращала строку, вместо числа:\r\n```C#\r\npublic static string FromBaseX(string value, string charset)\r\n{\r\n  if (String.IsNullOrEmpty(charset)) { throw new ArgumentNullException(\"charset\"); }\r\n  long result = 0;\r\n  int basis = charset.Length;\r\n  bool negative = value.StartsWith(\"-\");\r\n  if (negative) { value = value.Substring(1); }\r\n\tstring zeros = \"\";\r\n\tfor (int i = value.Length - 1; i >= 0; i -= 1)\r\n\t{\r\n\t\tlong n = Convert.ToInt64(charset.IndexOf(value[i]) * (Math.Pow(basis, (value.Length - i - 1))));\r\n\t\tif (n == 0)\r\n\t\t{\r\n\t\t\tzeros += \"0\";\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tzeros = \"\";\r\n\t\t}\r\n\t\tresult += n;\r\n\t}\r\n\t\r\n\tstring resultStr = zeros;\r\n\tif (negative) { resultStr = \"-\" + resultStr; }\r\n\tresultStr += result.ToString();\r\n\t\t\r\n\treturn resultStr;\r\n}\r\n```\r\n[Посмотреть работу примера](https://dotnetfiddle.net/oVRVW2).\r\n\r\nЛибо внедрить туда отсекание нулей через **TrimStart**.\r\n\r\nЯ бы выбрал вариант с **TrimStart**, он проще всего. Внедрять пока не буду, не вижу смысла, т.к. это вопрос форматирования строк, а не работы с числами. Еще обдумаю эту тему, но скорых действий в этом направлении с моей стороны ожидать не стоит."}}