mirror of
https://github.com/TheAlgorithms/C
synced 2024-12-15 07:52:36 +03:00
508 lines
40 KiB
HTML
508 lines
40 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
|
|
<meta name="generator" content="Doxygen 1.9.2"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
<title>Algorithms_in_C: conversions/decimal_to_any_base.c File Reference</title>
|
|
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="../../jquery.js"></script>
|
|
<script type="text/javascript" src="../../dynsections.js"></script>
|
|
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="../../resize.js"></script>
|
|
<script type="text/javascript" src="../../navtreedata.js"></script>
|
|
<script type="text/javascript" src="../../navtree.js"></script>
|
|
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
|
|
<script type="text/javascript" src="../../search/searchdata.js"></script>
|
|
<script type="text/javascript" src="../../search/search.js"></script>
|
|
<script type="text/x-mathjax-config">
|
|
MathJax.Hub.Config({
|
|
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
|
|
jax: ["input/TeX","output/HTML-CSS"],
|
|
});
|
|
</script>
|
|
<script type="text/javascript" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML/MathJax.js"></script>
|
|
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
|
|
</head>
|
|
<body>
|
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
|
<div id="titlearea">
|
|
<table cellspacing="0" cellpadding="0">
|
|
<tbody>
|
|
<tr style="height: 56px;">
|
|
<td id="projectalign" style="padding-left: 0.5em;">
|
|
<div id="projectname">Algorithms_in_C<span id="projectnumber"> 1.0.0</span>
|
|
</div>
|
|
<div id="projectbrief">Set of algorithms implemented in C.</div>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<!-- end header part -->
|
|
<!-- Generated by Doxygen 1.9.2 -->
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
var searchBox = new SearchBox("searchBox", "../../search",'Search','.html');
|
|
/* @license-end */
|
|
</script>
|
|
<script type="text/javascript" src="../../menudata.js"></script>
|
|
<script type="text/javascript" src="../../menu.js"></script>
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
$(function() {
|
|
initMenu('../../',true,false,'search.php','Search');
|
|
$(document).ready(function() { init_search(); });
|
|
});
|
|
/* @license-end */
|
|
</script>
|
|
<div id="main-nav"></div>
|
|
</div><!-- top -->
|
|
<div id="side-nav" class="ui-resizable side-nav-resizable">
|
|
<div id="nav-tree">
|
|
<div id="nav-tree-contents">
|
|
<div id="nav-sync" class="sync"></div>
|
|
</div>
|
|
</div>
|
|
<div id="splitbar" style="-moz-user-select:none;"
|
|
class="ui-resizable-handle">
|
|
</div>
|
|
</div>
|
|
<script type="text/javascript">
|
|
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
|
|
$(document).ready(function(){initNavTree('d1/dba/decimal__to__any__base_8c.html','../../'); initResizable(); });
|
|
/* @license-end */
|
|
</script>
|
|
<div id="doc-content">
|
|
<!-- window showing the filter options -->
|
|
<div id="MSearchSelectWindow"
|
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
|
</div>
|
|
|
|
<!-- iframe showing the search results (closed by default) -->
|
|
<div id="MSearchResultsWindow">
|
|
<iframe src="javascript:void(0)" frameborder="0"
|
|
name="MSearchResults" id="MSearchResults">
|
|
</iframe>
|
|
</div>
|
|
|
|
<div class="header">
|
|
<div class="summary">
|
|
<a href="#func-members">Functions</a> </div>
|
|
<div class="headertitle"><div class="title">decimal_to_any_base.c File Reference</div></div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
|
|
<p><a href="http://codeofthedamned.com/index.php/number-base-conversion" target="_blank">Decimal to any-base</a> is a C function wich convert positive decimal integer to any positive ascii base with the base's alphabet given in input and return it in a dynamically allocated string(recursive way)
|
|
<a href="#details">More...</a></p>
|
|
<div class="textblock"><code>#include <stdio.h></code><br />
|
|
<code>#include <string.h></code><br />
|
|
<code>#include <stdint.h></code><br />
|
|
<code>#include <stdbool.h></code><br />
|
|
<code>#include <assert.h></code><br />
|
|
<code>#include <stdlib.h></code><br />
|
|
</div><div class="textblock"><div class="dynheader">
|
|
Include dependency graph for decimal_to_any_base.c:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d8/d26/decimal__to__any__base_8c__incl.svg" width="532" height="127"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
</div><table class="memberdecls">
|
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
|
|
Functions</h2></td></tr>
|
|
<tr class="memitem:ae071f62d704823751bf9a085bf0a1bd7"><td class="memItemLeft" align="right" valign="top">bool </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d1/dba/decimal__to__any__base_8c.html#ae071f62d704823751bf9a085bf0a1bd7">isbad_alphabet</a> (const char *alphabet)</td></tr>
|
|
<tr class="memdesc:ae071f62d704823751bf9a085bf0a1bd7"><td class="mdescLeft"> </td><td class="mdescRight">for IO operations <a href="../../d1/dba/decimal__to__any__base_8c.html#ae071f62d704823751bf9a085bf0a1bd7">More...</a><br /></td></tr>
|
|
<tr class="separator:ae071f62d704823751bf9a085bf0a1bd7"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a899b3a7e0f1fac5a465eac0d4b10d711"><td class="memItemLeft" align="right" valign="top">uint64_t </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d1/dba/decimal__to__any__base_8c.html#a899b3a7e0f1fac5a465eac0d4b10d711">converted_len</a> (uint64_t nb, short base)</td></tr>
|
|
<tr class="memdesc:a899b3a7e0f1fac5a465eac0d4b10d711"><td class="mdescLeft"> </td><td class="mdescRight">Calculate the final length of the converted number. <a href="../../d1/dba/decimal__to__any__base_8c.html#a899b3a7e0f1fac5a465eac0d4b10d711">More...</a><br /></td></tr>
|
|
<tr class="separator:a899b3a7e0f1fac5a465eac0d4b10d711"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a0c5ccb926a23bc0050f213ba3408e18d"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d1/dba/decimal__to__any__base_8c.html#a0c5ccb926a23bc0050f213ba3408e18d">convertion</a> (uint64_t nb, const char *alphabet, short base, char *converted)</td></tr>
|
|
<tr class="memdesc:a0c5ccb926a23bc0050f213ba3408e18d"><td class="mdescLeft"> </td><td class="mdescRight">Convert positive decimal integer into anybase recursively. <a href="../../d1/dba/decimal__to__any__base_8c.html#a0c5ccb926a23bc0050f213ba3408e18d">More...</a><br /></td></tr>
|
|
<tr class="separator:a0c5ccb926a23bc0050f213ba3408e18d"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a3e4a7cfc97a528faa4d6e5741461109c"><td class="memItemLeft" align="right" valign="top">char * </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d1/dba/decimal__to__any__base_8c.html#a3e4a7cfc97a528faa4d6e5741461109c">decimal_to_anybase</a> (uint64_t nb, const char *alphabet)</td></tr>
|
|
<tr class="memdesc:a3e4a7cfc97a528faa4d6e5741461109c"><td class="mdescLeft"> </td><td class="mdescRight">decimal_to_anybase ensure the validity of the parameters and convert any unsigned integers into any ascii positive base <a href="../../d1/dba/decimal__to__any__base_8c.html#a3e4a7cfc97a528faa4d6e5741461109c">More...</a><br /></td></tr>
|
|
<tr class="separator:a3e4a7cfc97a528faa4d6e5741461109c"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:aa8dca7b867074164d5f45b0f3851269d"><td class="memItemLeft" align="right" valign="top">static void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d1/dba/decimal__to__any__base_8c.html#aa8dca7b867074164d5f45b0f3851269d">test</a> ()</td></tr>
|
|
<tr class="memdesc:aa8dca7b867074164d5f45b0f3851269d"><td class="mdescLeft"> </td><td class="mdescRight">Self-test implementations. <a href="../../d1/dba/decimal__to__any__base_8c.html#aa8dca7b867074164d5f45b0f3851269d">More...</a><br /></td></tr>
|
|
<tr class="separator:aa8dca7b867074164d5f45b0f3851269d"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d1/dba/decimal__to__any__base_8c.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a> ()</td></tr>
|
|
<tr class="memdesc:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="mdescLeft"> </td><td class="mdescRight">Main function. <a href="../../d1/dba/decimal__to__any__base_8c.html#ae66f6b31b5ad750f1fe042a706a4e3d4">More...</a><br /></td></tr>
|
|
<tr class="separator:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memSeparator" colspan="2"> </td></tr>
|
|
</table>
|
|
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
|
|
<div class="textblock"><p ><a href="http://codeofthedamned.com/index.php/number-base-conversion" target="_blank">Decimal to any-base</a> is a C function wich convert positive decimal integer to any positive ascii base with the base's alphabet given in input and return it in a dynamically allocated string(recursive way) </p>
|
|
<dl class="section author"><dt>Author</dt><dd><a href="https://github.com/jucollet972" target="_blank">jucollet972</a> </dd></dl>
|
|
</div><h2 class="groupheader">Function Documentation</h2>
|
|
<a id="a899b3a7e0f1fac5a465eac0d4b10d711" name="a899b3a7e0f1fac5a465eac0d4b10d711"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a899b3a7e0f1fac5a465eac0d4b10d711">◆ </a></span>converted_len()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">uint64_t converted_len </td>
|
|
<td>(</td>
|
|
<td class="paramtype">uint64_t </td>
|
|
<td class="paramname"><em>nb</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">short </td>
|
|
<td class="paramname"><em>base</em> </td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td>)</td>
|
|
<td></td><td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Calculate the final length of the converted number. </p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">nb</td><td>to convert </td></tr>
|
|
<tr><td class="paramname">base</td><td>calculated from alphabet </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>Converted nb string length </dd></dl>
|
|
<div class="fragment"><div class="line"><a id="l00042" name="l00042"></a><span class="lineno"> 42</span> {</div>
|
|
<div class="line"><a id="l00043" name="l00043"></a><span class="lineno"> 43</span> <span class="comment">/* Counting the number of characters translated to the base*/</span></div>
|
|
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno"> 44</span> <span class="keywordflow">if</span> (nb > base - 1) {</div>
|
|
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno"> 45</span> <span class="keywordflow">return</span> (<a class="code hl_function" href="../../d1/dba/decimal__to__any__base_8c.html#a899b3a7e0f1fac5a465eac0d4b10d711">converted_len</a>(nb/base, base) + 1);</div>
|
|
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno"> 46</span> }</div>
|
|
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno"> 47</span> <span class="keywordflow">return</span> 1;</div>
|
|
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno"> 48</span>}</div>
|
|
<div class="ttc" id="adecimal__to__any__base_8c_html_a899b3a7e0f1fac5a465eac0d4b10d711"><div class="ttname"><a href="../../d1/dba/decimal__to__any__base_8c.html#a899b3a7e0f1fac5a465eac0d4b10d711">converted_len</a></div><div class="ttdeci">uint64_t converted_len(uint64_t nb, short base)</div><div class="ttdoc">Calculate the final length of the converted number.</div><div class="ttdef"><b>Definition:</b> decimal_to_any_base.c:42</div></div>
|
|
</div><!-- fragment --><div class="dynheader">
|
|
Here is the call graph for this function:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d1/dba/decimal__to__any__base_8c_a899b3a7e0f1fac5a465eac0d4b10d711_cgraph.svg" width="114" height="62"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="a0c5ccb926a23bc0050f213ba3408e18d" name="a0c5ccb926a23bc0050f213ba3408e18d"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a0c5ccb926a23bc0050f213ba3408e18d">◆ </a></span>convertion()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void convertion </td>
|
|
<td>(</td>
|
|
<td class="paramtype">uint64_t </td>
|
|
<td class="paramname"><em>nb</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">const char * </td>
|
|
<td class="paramname"><em>alphabet</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">short </td>
|
|
<td class="paramname"><em>base</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">char * </td>
|
|
<td class="paramname"><em>converted</em> </td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td>)</td>
|
|
<td></td><td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Convert positive decimal integer into anybase recursively. </p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">nb</td><td>to convert </td></tr>
|
|
<tr><td class="paramname">alphabet</td><td>inputed by user used for base convertion </td></tr>
|
|
<tr><td class="paramname">base</td><td>calculated from alphabet </td></tr>
|
|
<tr><td class="paramname">converted</td><td>string filled with the convertion's result </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
|
|
<div class="fragment"><div class="line"><a id="l00058" name="l00058"></a><span class="lineno"> 58</span> {</div>
|
|
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno"> 59</span> <span class="comment">/* Recursive convertion */</span></div>
|
|
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno"> 60</span> *(converted) = *(alphabet + nb%base);</div>
|
|
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno"> 61</span> <span class="keywordflow">if</span> (nb > base - 1) {</div>
|
|
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno"> 62</span> <a class="code hl_function" href="../../d1/dba/decimal__to__any__base_8c.html#a0c5ccb926a23bc0050f213ba3408e18d">convertion</a>(nb/base, alphabet, base, --converted);</div>
|
|
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno"> 63</span> }</div>
|
|
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno"> 64</span>}</div>
|
|
<div class="ttc" id="adecimal__to__any__base_8c_html_a0c5ccb926a23bc0050f213ba3408e18d"><div class="ttname"><a href="../../d1/dba/decimal__to__any__base_8c.html#a0c5ccb926a23bc0050f213ba3408e18d">convertion</a></div><div class="ttdeci">void convertion(uint64_t nb, const char *alphabet, short base, char *converted)</div><div class="ttdoc">Convert positive decimal integer into anybase recursively.</div><div class="ttdef"><b>Definition:</b> decimal_to_any_base.c:58</div></div>
|
|
</div><!-- fragment --><div class="dynheader">
|
|
Here is the call graph for this function:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d1/dba/decimal__to__any__base_8c_a0c5ccb926a23bc0050f213ba3408e18d_cgraph.svg" width="94" height="62"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="a3e4a7cfc97a528faa4d6e5741461109c" name="a3e4a7cfc97a528faa4d6e5741461109c"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a3e4a7cfc97a528faa4d6e5741461109c">◆ </a></span>decimal_to_anybase()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">char * decimal_to_anybase </td>
|
|
<td>(</td>
|
|
<td class="paramtype">uint64_t </td>
|
|
<td class="paramname"><em>nb</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">const char * </td>
|
|
<td class="paramname"><em>alphabet</em> </td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td>)</td>
|
|
<td></td><td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>decimal_to_anybase ensure the validity of the parameters and convert any unsigned integers into any ascii positive base </p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">nb</td><td>to convert </td></tr>
|
|
<tr><td class="paramname">base's</td><td>alphabet </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>nb converted on success </dd>
|
|
<dd>
|
|
NULL on error </dd></dl>
|
|
<div class="fragment"><div class="line"><a id="l00073" name="l00073"></a><span class="lineno"> 73</span> {</div>
|
|
<div class="line"><a id="l00074" name="l00074"></a><span class="lineno"> 74</span> <span class="keywordtype">char</span>* converted;</div>
|
|
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno"> 75</span> </div>
|
|
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno"> 76</span> <span class="comment">/* Verify that alphabet is valid */</span></div>
|
|
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno"> 77</span> <span class="keywordflow">if</span> (<a class="code hl_function" href="../../d1/dba/decimal__to__any__base_8c.html#ae071f62d704823751bf9a085bf0a1bd7">isbad_alphabet</a>(alphabet)) {</div>
|
|
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno"> 78</span> <span class="keywordflow">return</span> NULL;</div>
|
|
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno"> 79</span> }</div>
|
|
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno"> 80</span> <span class="comment">/* Convertion */</span></div>
|
|
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno"> 81</span> uint64_t base = strlen(alphabet);</div>
|
|
<div class="line"><a id="l00082" name="l00082"></a><span class="lineno"> 82</span> uint64_t final_len = <a class="code hl_function" href="../../d1/dba/decimal__to__any__base_8c.html#a899b3a7e0f1fac5a465eac0d4b10d711">converted_len</a>(nb, base);</div>
|
|
<div class="line"><a id="l00083" name="l00083"></a><span class="lineno"> 83</span> converted = <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a>(<span class="keyword">sizeof</span>(<span class="keywordtype">char</span>) * (final_len + 1));</div>
|
|
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno"> 84</span> converted[final_len] = 0;</div>
|
|
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno"> 85</span> <a class="code hl_function" href="../../d1/dba/decimal__to__any__base_8c.html#a0c5ccb926a23bc0050f213ba3408e18d">convertion</a>(nb, alphabet, base, converted + final_len - 1);</div>
|
|
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno"> 86</span> <span class="keywordflow">return</span> converted;</div>
|
|
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno"> 87</span>}</div>
|
|
<div class="ttc" id="adecimal__to__any__base_8c_html_ae071f62d704823751bf9a085bf0a1bd7"><div class="ttname"><a href="../../d1/dba/decimal__to__any__base_8c.html#ae071f62d704823751bf9a085bf0a1bd7">isbad_alphabet</a></div><div class="ttdeci">bool isbad_alphabet(const char *alphabet)</div><div class="ttdoc">for IO operations</div><div class="ttdef"><b>Definition:</b> decimal_to_any_base.c:20</div></div>
|
|
<div class="ttc" id="amalloc__dbg_8h_html_a725f50ecaf1959d96de79b36b4788fee"><div class="ttname"><a href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a></div><div class="ttdeci">#define malloc(bytes)</div><div class="ttdoc">This macro replace the standard malloc function with malloc_dbg.</div><div class="ttdef"><b>Definition:</b> malloc_dbg.h:18</div></div>
|
|
</div><!-- fragment --><div class="dynheader">
|
|
Here is the call graph for this function:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d1/dba/decimal__to__any__base_8c_a3e4a7cfc97a528faa4d6e5741461109c_cgraph.svg" width="310" height="187"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="ae071f62d704823751bf9a085bf0a1bd7" name="ae071f62d704823751bf9a085bf0a1bd7"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#ae071f62d704823751bf9a085bf0a1bd7">◆ </a></span>isbad_alphabet()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">bool isbad_alphabet </td>
|
|
<td>(</td>
|
|
<td class="paramtype">const char * </td>
|
|
<td class="paramname"><em>alphabet</em></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>for IO operations </p>
|
|
<p >for strchr and strlen for CPU arch's optimized int types for boolean types for assert for malloc and free</p>
|
|
<p >Checking if alphabet is valid </p><dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramname">base</td><td>alphabet inputed by user </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>int64_t as success or not </dd></dl>
|
|
<div class="fragment"><div class="line"><a id="l00020" name="l00020"></a><span class="lineno"> 20</span> {</div>
|
|
<div class="line"><a id="l00021" name="l00021"></a><span class="lineno"> 21</span> uint64_t len = strlen(alphabet);</div>
|
|
<div class="line"><a id="l00022" name="l00022"></a><span class="lineno"> 22</span> </div>
|
|
<div class="line"><a id="l00023" name="l00023"></a><span class="lineno"> 23</span> <span class="comment">/* Checking th lenght */</span> </div>
|
|
<div class="line"><a id="l00024" name="l00024"></a><span class="lineno"> 24</span> <span class="keywordflow">if</span> (len < 2) {</div>
|
|
<div class="line"><a id="l00025" name="l00025"></a><span class="lineno"> 25</span> <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
|
|
<div class="line"><a id="l00026" name="l00026"></a><span class="lineno"> 26</span> }</div>
|
|
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno"> 27</span> <span class="comment">/* Browse the alphabet */</span></div>
|
|
<div class="line"><a id="l00028" name="l00028"></a><span class="lineno"> 28</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < len ; i++) {</div>
|
|
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno"> 29</span> <span class="comment">/* Searching for duplicates */</span> </div>
|
|
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno"> 30</span> <span class="keywordflow">if</span> (strchr(alphabet + i + 1, alphabet[i]))</div>
|
|
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno"> 31</span> <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
|
|
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno"> 32</span> }</div>
|
|
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno"> 33</span> <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
|
|
<div class="line"><a id="l00034" name="l00034"></a><span class="lineno"> 34</span>}</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="ae66f6b31b5ad750f1fe042a706a4e3d4" name="ae66f6b31b5ad750f1fe042a706a4e3d4"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#ae66f6b31b5ad750f1fe042a706a4e3d4">◆ </a></span>main()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">int main </td>
|
|
<td>(</td>
|
|
<td class="paramtype">void </td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Main function. </p>
|
|
<dl class="section return"><dt>Returns</dt><dd>0 on exit </dd></dl>
|
|
<div class="fragment"><div class="line"><a id="l00166" name="l00166"></a><span class="lineno"> 166</span>{</div>
|
|
<div class="line"><a id="l00167" name="l00167"></a><span class="lineno"> 167</span> <a class="code hl_function" href="../../d1/dba/decimal__to__any__base_8c.html#aa8dca7b867074164d5f45b0f3851269d">test</a>(); <span class="comment">// run self-test implementations</span></div>
|
|
<div class="line"><a id="l00168" name="l00168"></a><span class="lineno"> 168</span> <span class="keywordflow">return</span> 0;</div>
|
|
<div class="line"><a id="l00169" name="l00169"></a><span class="lineno"> 169</span>}</div>
|
|
<div class="ttc" id="adecimal__to__any__base_8c_html_aa8dca7b867074164d5f45b0f3851269d"><div class="ttname"><a href="../../d1/dba/decimal__to__any__base_8c.html#aa8dca7b867074164d5f45b0f3851269d">test</a></div><div class="ttdeci">static void test()</div><div class="ttdoc">Self-test implementations.</div><div class="ttdef"><b>Definition:</b> decimal_to_any_base.c:94</div></div>
|
|
</div><!-- fragment --><div class="dynheader">
|
|
Here is the call graph for this function:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d1/dba/decimal__to__any__base_8c_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg" width="500" height="187"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="aa8dca7b867074164d5f45b0f3851269d" name="aa8dca7b867074164d5f45b0f3851269d"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#aa8dca7b867074164d5f45b0f3851269d">◆ </a></span>test()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="mlabels">
|
|
<tr>
|
|
<td class="mlabels-left">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">static void test </td>
|
|
<td>(</td>
|
|
<td class="paramtype">void </td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</td>
|
|
<td class="mlabels-right">
|
|
<span class="mlabels"><span class="mlabel">static</span></span> </td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Self-test implementations. </p>
|
|
<dl class="section return"><dt>Returns</dt><dd>void </dd></dl>
|
|
<div class="fragment"><div class="line"><a id="l00095" name="l00095"></a><span class="lineno"> 95</span>{</div>
|
|
<div class="line"><a id="l00096" name="l00096"></a><span class="lineno"> 96</span> <span class="keywordtype">char</span>* ret = NULL;</div>
|
|
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno"> 97</span> <span class="keywordtype">char</span>* reference = NULL;</div>
|
|
<div class="line"><a id="l00098" name="l00098"></a><span class="lineno"> 98</span> </div>
|
|
<div class="line"><a id="l00099" name="l00099"></a><span class="lineno"> 99</span> <span class="comment">/* min dec*/</span></div>
|
|
<div class="line"><a id="l00100" name="l00100"></a><span class="lineno"> 100</span> reference = <span class="stringliteral">"0"</span>;</div>
|
|
<div class="line"><a id="l00101" name="l00101"></a><span class="lineno"> 101</span> ret = <a class="code hl_function" href="../../d1/dba/decimal__to__any__base_8c.html#a3e4a7cfc97a528faa4d6e5741461109c">decimal_to_anybase</a>(0, <span class="stringliteral">"0123456789"</span>);</div>
|
|
<div class="line"><a id="l00102" name="l00102"></a><span class="lineno"> 102</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < strlen(reference) && i < strlen(ret); i++) {</div>
|
|
<div class="line"><a id="l00103" name="l00103"></a><span class="lineno"> 103</span> assert(ret[i] == reference[i]);</div>
|
|
<div class="line"><a id="l00104" name="l00104"></a><span class="lineno"> 104</span> }</div>
|
|
<div class="line"><a id="l00105" name="l00105"></a><span class="lineno"> 105</span> <span class="keywordflow">if</span> (ret != NULL) {</div>
|
|
<div class="line"><a id="l00106" name="l00106"></a><span class="lineno"> 106</span> <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(ret);</div>
|
|
<div class="line"><a id="l00107" name="l00107"></a><span class="lineno"> 107</span> }</div>
|
|
<div class="line"><a id="l00108" name="l00108"></a><span class="lineno"> 108</span> </div>
|
|
<div class="line"><a id="l00109" name="l00109"></a><span class="lineno"> 109</span> <span class="comment">/* max dec*/</span></div>
|
|
<div class="line"><a id="l00110" name="l00110"></a><span class="lineno"> 110</span> reference = <span class="stringliteral">"18446744073709551615"</span>;</div>
|
|
<div class="line"><a id="l00111" name="l00111"></a><span class="lineno"> 111</span> ret = <a class="code hl_function" href="../../d1/dba/decimal__to__any__base_8c.html#a3e4a7cfc97a528faa4d6e5741461109c">decimal_to_anybase</a>(18446744073709551615, <span class="stringliteral">"0123456789"</span>);</div>
|
|
<div class="line"><a id="l00112" name="l00112"></a><span class="lineno"> 112</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < strlen(reference) && i < strlen(ret); i++) {</div>
|
|
<div class="line"><a id="l00113" name="l00113"></a><span class="lineno"> 113</span> assert(ret[i] == reference[i]);</div>
|
|
<div class="line"><a id="l00114" name="l00114"></a><span class="lineno"> 114</span> }</div>
|
|
<div class="line"><a id="l00115" name="l00115"></a><span class="lineno"> 115</span> <span class="keywordflow">if</span> (ret != NULL) {</div>
|
|
<div class="line"><a id="l00116" name="l00116"></a><span class="lineno"> 116</span> <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(ret);</div>
|
|
<div class="line"><a id="l00117" name="l00117"></a><span class="lineno"> 117</span> }</div>
|
|
<div class="line"><a id="l00118" name="l00118"></a><span class="lineno"> 118</span> </div>
|
|
<div class="line"><a id="l00119" name="l00119"></a><span class="lineno"> 119</span> <span class="comment">/* negative dec*/</span></div>
|
|
<div class="line"><a id="l00120" name="l00120"></a><span class="lineno"> 120</span> reference = <span class="stringliteral">"18446744073709551615"</span>;</div>
|
|
<div class="line"><a id="l00121" name="l00121"></a><span class="lineno"> 121</span> ret = <a class="code hl_function" href="../../d1/dba/decimal__to__any__base_8c.html#a3e4a7cfc97a528faa4d6e5741461109c">decimal_to_anybase</a>(-1, <span class="stringliteral">"0123456789"</span>);</div>
|
|
<div class="line"><a id="l00122" name="l00122"></a><span class="lineno"> 122</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < strlen(reference) && i < strlen(ret); i++) {</div>
|
|
<div class="line"><a id="l00123" name="l00123"></a><span class="lineno"> 123</span> assert(ret[i] == reference[i]);</div>
|
|
<div class="line"><a id="l00124" name="l00124"></a><span class="lineno"> 124</span> }</div>
|
|
<div class="line"><a id="l00125" name="l00125"></a><span class="lineno"> 125</span> <span class="keywordflow">if</span> (ret != NULL) {</div>
|
|
<div class="line"><a id="l00126" name="l00126"></a><span class="lineno"> 126</span> <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(ret);</div>
|
|
<div class="line"><a id="l00127" name="l00127"></a><span class="lineno"> 127</span> }</div>
|
|
<div class="line"><a id="l00128" name="l00128"></a><span class="lineno"> 128</span> </div>
|
|
<div class="line"><a id="l00129" name="l00129"></a><span class="lineno"> 129</span> <span class="comment">/* bin */</span></div>
|
|
<div class="line"><a id="l00130" name="l00130"></a><span class="lineno"> 130</span> reference = <span class="stringliteral">"101010"</span>;</div>
|
|
<div class="line"><a id="l00131" name="l00131"></a><span class="lineno"> 131</span> ret = <a class="code hl_function" href="../../d1/dba/decimal__to__any__base_8c.html#a3e4a7cfc97a528faa4d6e5741461109c">decimal_to_anybase</a>(42, <span class="stringliteral">"01"</span>);</div>
|
|
<div class="line"><a id="l00132" name="l00132"></a><span class="lineno"> 132</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < strlen(reference) && i < strlen(ret); i++) {</div>
|
|
<div class="line"><a id="l00133" name="l00133"></a><span class="lineno"> 133</span> assert(ret[i] == reference[i]);</div>
|
|
<div class="line"><a id="l00134" name="l00134"></a><span class="lineno"> 134</span> }</div>
|
|
<div class="line"><a id="l00135" name="l00135"></a><span class="lineno"> 135</span> <span class="keywordflow">if</span> (ret != NULL) {</div>
|
|
<div class="line"><a id="l00136" name="l00136"></a><span class="lineno"> 136</span> <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(ret);</div>
|
|
<div class="line"><a id="l00137" name="l00137"></a><span class="lineno"> 137</span> }</div>
|
|
<div class="line"><a id="l00138" name="l00138"></a><span class="lineno"> 138</span> </div>
|
|
<div class="line"><a id="l00139" name="l00139"></a><span class="lineno"> 139</span> <span class="comment">/* octal */</span></div>
|
|
<div class="line"><a id="l00140" name="l00140"></a><span class="lineno"> 140</span> reference = <span class="stringliteral">"52"</span>;</div>
|
|
<div class="line"><a id="l00141" name="l00141"></a><span class="lineno"> 141</span> ret = <a class="code hl_function" href="../../d1/dba/decimal__to__any__base_8c.html#a3e4a7cfc97a528faa4d6e5741461109c">decimal_to_anybase</a>(42, <span class="stringliteral">"01234567"</span>);</div>
|
|
<div class="line"><a id="l00142" name="l00142"></a><span class="lineno"> 142</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < strlen(reference) && i < strlen(ret); i++) {</div>
|
|
<div class="line"><a id="l00143" name="l00143"></a><span class="lineno"> 143</span> assert(ret[i] == reference[i]);</div>
|
|
<div class="line"><a id="l00144" name="l00144"></a><span class="lineno"> 144</span> }</div>
|
|
<div class="line"><a id="l00145" name="l00145"></a><span class="lineno"> 145</span> <span class="keywordflow">if</span> (ret != NULL) {</div>
|
|
<div class="line"><a id="l00146" name="l00146"></a><span class="lineno"> 146</span> <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(ret);</div>
|
|
<div class="line"><a id="l00147" name="l00147"></a><span class="lineno"> 147</span> }</div>
|
|
<div class="line"><a id="l00148" name="l00148"></a><span class="lineno"> 148</span> </div>
|
|
<div class="line"><a id="l00149" name="l00149"></a><span class="lineno"> 149</span> <span class="comment">/* hexa */</span></div>
|
|
<div class="line"><a id="l00150" name="l00150"></a><span class="lineno"> 150</span> reference = <span class="stringliteral">"2A"</span>;</div>
|
|
<div class="line"><a id="l00151" name="l00151"></a><span class="lineno"> 151</span> ret = <a class="code hl_function" href="../../d1/dba/decimal__to__any__base_8c.html#a3e4a7cfc97a528faa4d6e5741461109c">decimal_to_anybase</a>(42, <span class="stringliteral">"0123456789ABCDEF"</span>);</div>
|
|
<div class="line"><a id="l00152" name="l00152"></a><span class="lineno"> 152</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < strlen(reference) && i < strlen(ret); i++) {</div>
|
|
<div class="line"><a id="l00153" name="l00153"></a><span class="lineno"> 153</span> assert(ret[i] == reference[i]);</div>
|
|
<div class="line"><a id="l00154" name="l00154"></a><span class="lineno"> 154</span> }</div>
|
|
<div class="line"><a id="l00155" name="l00155"></a><span class="lineno"> 155</span> <span class="keywordflow">if</span> (ret != NULL) {</div>
|
|
<div class="line"><a id="l00156" name="l00156"></a><span class="lineno"> 156</span> <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(ret);</div>
|
|
<div class="line"><a id="l00157" name="l00157"></a><span class="lineno"> 157</span> }</div>
|
|
<div class="line"><a id="l00158" name="l00158"></a><span class="lineno"> 158</span> printf(<span class="stringliteral">"[+] All tests have successfully passed!\n"</span>);</div>
|
|
<div class="line"><a id="l00159" name="l00159"></a><span class="lineno"> 159</span>}</div>
|
|
<div class="ttc" id="adecimal__to__any__base_8c_html_a3e4a7cfc97a528faa4d6e5741461109c"><div class="ttname"><a href="../../d1/dba/decimal__to__any__base_8c.html#a3e4a7cfc97a528faa4d6e5741461109c">decimal_to_anybase</a></div><div class="ttdeci">char * decimal_to_anybase(uint64_t nb, const char *alphabet)</div><div class="ttdoc">decimal_to_anybase ensure the validity of the parameters and convert any unsigned integers into any a...</div><div class="ttdef"><b>Definition:</b> decimal_to_any_base.c:73</div></div>
|
|
<div class="ttc" id="amalloc__dbg_8h_html_a9cc854374299a1dd933bf62029761768"><div class="ttname"><a href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a></div><div class="ttdeci">#define free(ptr)</div><div class="ttdoc">This macro replace the standard free function with free_dbg.</div><div class="ttdef"><b>Definition:</b> malloc_dbg.h:26</div></div>
|
|
</div><!-- fragment --><div class="dynheader">
|
|
Here is the call graph for this function:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d1/dba/decimal__to__any__base_8c_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg" width="402" height="187"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</div><!-- contents -->
|
|
</div><!-- doc-content -->
|
|
<!-- start footer part -->
|
|
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
|
<ul>
|
|
<li class="navelem"><a class="el" href="../../dir_9babc524d57e25f3d9f4179cabc3599e.html">conversions</a></li><li class="navelem"><a class="el" href="../../d1/dba/decimal__to__any__base_8c.html">decimal_to_any_base.c</a></li>
|
|
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.2 </li>
|
|
</ul>
|
|
</div>
|
|
</body>
|
|
</html>
|