bitxor of two numbers

1 次查看(过去 30 天)
Asha D.
Asha D. 2019-12-5
回答: Asha D. 2019-12-6
I am using the following code to generate random sequence. But error message' Double inputs must have integer values in the range of ASSUMEDTYPE.' is coming. PLS HELP.
function [xout,yout, x0, y0] = ginger(x0,y0)
% Gingerbreadman map producing a chaotic 2-D map.
% if not enough inputs, assign random numbers
if nargin < 2
x0 = randn();
y0 = randn();
end
% iteration counter
n = 20000;
x = zeros(n,1);
y = zeros(n,1);
% main calculation
% Taking different values of r from 0.2 to 3.8. we can take
%cos also insted of sine.
for i = 1:n
if i == 1
x(i) = 1 - y0 + abs(x0);
y(i) = x0+3.8*cos(y0);
else
x(i) = 1 - y(i-1) + abs(x(i-1));
y(i) = x(i-1)+3.8*cos(y(i-1));
end
end
% if output is requested, return gingerbread x,y values and
% x0, y0 initial conditions
% otherwise plot results
if nargout > 0
xout = x;
yout = y;
else
scatter(x, y, '.');
c=bitxor(x,y);
end
  1 个评论
Walter Roberson
Walter Roberson 2019-12-5
c is not an output and is not used later on. Why are you calculating it?

请先登录,再进行评论。

回答(2 个)

Walter Roberson
Walter Roberson 2019-12-5
c = typecast( bitxor(typecast(x, 'uint64'), typecast(y, 'uint64')), 'double');
Expect to see a lot of values in the range 1e-308, and be aware that creating a double out of arbitrary bit streams can leave you with values that are denormalized or are one of the many many different kinds of nan or "signaling nan". You can create values that, if MATLAB were to take you seriously, would result in MATLAB creating an error message about invalid operations (signalling nans), except MATLAB will not take you seriously. Also note that MATLAB treats all nans the same for most purposes, so once you have managed to create these nans, you will have a hard time telling them apart.
All in all, doing a bitxor between two doubles is a Bad Idea.
  2 个评论
Asha D.
Asha D. 2019-12-5
Thank you very much for the timely help. I want to create a psuedo random sequence using 2D gingerman map. So I thought of bitxoring....what is the other way possible...pls suggest.
Walter Roberson
Walter Roberson 2019-12-5
Should the pseudo-random sequence be integer or floating point? What range should it have? What distribution should it have (ideally) ?

请先登录,再进行评论。


Asha D.
Asha D. 2019-12-6
Actually I want it for image steganography...for color image...so it should be integer.

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by