bitxor of two numbers

2 views (last 30 days)
Asha D.
Asha D. on 5 Dec 2019
Answered: Asha D. on 6 Dec 2019
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 Comment
Walter Roberson
Walter Roberson on 5 Dec 2019
c is not an output and is not used later on. Why are you calculating it?

Sign in to comment.

Answers (2)

Walter Roberson
Walter Roberson on 5 Dec 2019
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 Comments
Asha D.
Asha D. on 5 Dec 2019
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 on 5 Dec 2019
Should the pseudo-random sequence be integer or floating point? What range should it have? What distribution should it have (ideally) ?

Sign in to comment.


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

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!