Jump to content

Entropy: Difference between revisions

m
→‎version 2: added/changed whitespace.
m (→‎version 2: fixed closing tag for HTML string.)
m (→‎version 2: added/changed whitespace.)
Line 2,527:
 
The &nbsp; '''LOG2''' &nbsp; subroutine is only included here for functionality, not to document how to calculate &nbsp; LOG<sub>2</sub> &nbsp; using REXX.
<lang rexx>/*REXX program calculates the information entropy for a givenspecified character string. */
numeric digits length( e() ) % 2 - length(.) /*use 1/2 of the decimal digits of E. */
parse arg $; if $='' then $= 1223334444 /*obtain the optional input from the CL*/
#=0 ; @.= 0; L= length($) /*define handy-dandy REXX variables. */
$$= /*initialize the $$ list. */
do j=1 for L; _= substr($, j, 1) /*process each character in $ string.*/
Line 2,544:
say ' input string: ' $
say 'string length: ' L
say ' unique chars: ' # ; say
say 'the information entropy of the string ──► ' format(sum,,12) " bits."
exit /*stick a fork in it, we're all done. */
Line 2,556:
ox=izz; ii=ii+is*2**j; end /*while*/; x= x * e** -ii -1; z= 0; _= -1; p= z
do k=1; _= -_ * x; z= z+_/k; if z=p then leave; p= z; end /*k*/
r= z + ii; if arg()==2 then return r; return r / log2(2, .)</lang>
{{out|output|text=&nbsp; when using the default input of: &nbsp; &nbsp; <tt> 1223334444 </tt>}}
<pre>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.