From: <sla...@us...> - 2008-07-27 12:41:38
|
Revision: 5202 http://octave.svn.sourceforge.net/octave/?rev=5202&view=rev Author: slackydeb Date: 2008-07-27 12:41:48 +0000 (Sun, 27 Jul 2008) Log Message: ----------- made ga tests working again; bug solved observing that a double precision number is always 64 bit long (not less) Modified Paths: -------------- trunk/octave-forge/main/ga/DESCRIPTION trunk/octave-forge/main/ga/inst/__bin2hex__.m trunk/octave-forge/main/ga/inst/__hex2bin__.m trunk/octave-forge/main/ga/inst/__num2bin__.m Modified: trunk/octave-forge/main/ga/DESCRIPTION =================================================================== --- trunk/octave-forge/main/ga/DESCRIPTION 2008-07-27 01:03:25 UTC (rev 5201) +++ trunk/octave-forge/main/ga/DESCRIPTION 2008-07-27 12:41:48 UTC (rev 5202) @@ -1,5 +1,5 @@ Name: ga -Version: 0.1.2 +Version: 0.2 Date: 2008-07-23 Author: Luca Favatella <sla...@gm...> Maintainer: Luca Favatella <sla...@gm...> Modified: trunk/octave-forge/main/ga/inst/__bin2hex__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__bin2hex__.m 2008-07-27 01:03:25 UTC (rev 5201) +++ trunk/octave-forge/main/ga/inst/__bin2hex__.m 2008-07-27 12:41:48 UTC (rev 5202) @@ -29,13 +29,13 @@ ## ## @example ## __bin2hex__ (["1101110"; "1110"]) -## @result{} [6E; 0E] +## @result{} [6E; E] ## @end example ## @seealso{__hex2bin__, bin2dec, dec2hex} ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 1.4 +## Version: 1.5 function h = __bin2hex__ (b) h = dec2hex (bin2dec (b)); @@ -43,4 +43,4 @@ %!assert (__bin2hex__ ("1101110"), "6E") -%!assert (__bin2hex__ (["1101110"; "1110"]), ["6E"; "0E"]) \ No newline at end of file +%!assert (__bin2hex__ (["1101110"; "1110"]), ["6E"; "E"]) \ No newline at end of file Modified: trunk/octave-forge/main/ga/inst/__hex2bin__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__hex2bin__.m 2008-07-27 01:03:25 UTC (rev 5201) +++ trunk/octave-forge/main/ga/inst/__hex2bin__.m 2008-07-27 12:41:48 UTC (rev 5202) @@ -17,7 +17,7 @@ ## 02110-1301, USA. ## -*- texinfo -*- -## @deftypefn {Function File} {} __hex2bin__ (@var{s}) +## @deftypefn {Function File} {} __hex2bin__ (@var{s}, @var{len}) ## Return the binary number corresponding to the hexadecimal number stored in the string @var{s}. For example, ## ## @example @@ -25,18 +25,33 @@ ## @result{} 1101110 ## @end example ## -## If @var{s} is a string matrix, returns a column vector of converted numbers, one per row of @var{s}. +## If @var{s} is a string matrix, returns a column vector of converted numbers, one per row of @var{s}, padded with leading zeros to the width of the largest value. ## ## @example ## __hex2bin__ (["6E"; "E"]) ## @result{} [1101110; 0001110] ## @end example +## +## The optional third argument, @var{len}, specifies the minimum +## number of digits in the result. + ## @seealso{__bin2hex__, hex2dec, dec2bin} ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 1.3 +## Version: 1.7 -function b = __hex2bin__ (h) - b = dec2bin (hex2dec (h)); -endfunction \ No newline at end of file +function b = __hex2bin__ (h, len) + d = hex2dec (h); + + switch nargin + case {1} + b = dec2bin (d); + case {2} + b = dec2bin (d, len); + endswitch +endfunction + +%!assert (__hex2bin__ ("6E"), "1101110") + +%!assert (__hex2bin__ (["6E"; "0E"]), ["1101110"; "0001110"]) \ No newline at end of file Modified: trunk/octave-forge/main/ga/inst/__num2bin__.m =================================================================== --- trunk/octave-forge/main/ga/inst/__num2bin__.m 2008-07-27 01:03:25 UTC (rev 5201) +++ trunk/octave-forge/main/ga/inst/__num2bin__.m 2008-07-27 12:41:48 UTC (rev 5202) @@ -35,8 +35,13 @@ ## @end deftypefn ## Author: Luca Favatella <sla...@gm...> -## Version: 1.2 +## Version: 1.4 function b = __num2bin__ (n) - b = __hex2bin__ (num2hex (n)); -endfunction \ No newline at end of file + ## a double precision number is always 64 bits long + b = __hex2bin__ (num2hex (n), 64); +endfunction + +%!assert (__num2bin__ (1), "0011111111110000000000000000000000000000000000000000000000000000") + +%!assert (__num2bin__ ([1; -3]), ["0011111111110000000000000000000000000000000000000000000000000000"; "1100000000001000000000000000000000000000000000000000000000000000"]) \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |