Mercurial > hg > octave-lyh
diff scripts/strings/bin2dec.m @ 14478:e995b1c97e13 stable
Fix regression in bin2dec which did not allow space-separated input.
* base2dec.m: Squeeze spaces from input before applying algorithm.
* bin2dec.m: Add tests for using spaces in binary number.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Fri, 16 Mar 2012 16:51:06 -0700 |
parents | 72c96de7a403 |
children | 5bd9e47e9277 |
line wrap: on
line diff
--- a/scripts/strings/bin2dec.m +++ b/scripts/strings/bin2dec.m @@ -28,6 +28,16 @@ ## @end group ## @end example ## +## Spaces are ignored during conversion and may be used to make the binary +## number more readable. +## +## @example +## @group +## bin2dec ("1000 0001") +## @result{} 129 +## @end group +## @end example +## ## If @var{s} is a string matrix, return a column vector with one converted ## number per row of @var{s}; Invalid rows evaluate to NaN@. ## @@ -54,6 +64,8 @@ %!assert(bin2dec ("1110"), 14); %!assert(bin2dec ("11111111111111111111111111111111111111111111111111111"), 2^53-1); %!assert(bin2dec ({"1110", "1111"}), [14; 15]); +%!assert (bin2dec ("1 0 1"), 5) +%!assert (bin2dec (char ("1 0 1", " 1111")), [5; 15]); %%Test input validation %!error bin2dec ();