Generate a 32-bit binary stream

조회 수: 5 (최근 30일)
Steve Rogerson
Steve Rogerson 2020년 2월 21일
댓글: Steve Rogerson 2020년 2월 26일
I am trying to genrate a binary stream using this function and have searched a lot but came out emty.
The main problem I am facing is mainly the binary addition on every addition and the size of the increasing stream.
The Equation is below:
I tried to use the rand fucntion but it isnt right. I realised the Binary addition was not happening.
The final result should be a float number within [0,1).
pold = [];
pf=0;
for i=1:32
param = round(rand(1,1));
pf = param + pf;
pold(i) = pf*2^(-i);
pold(i);
end

채택된 답변

Walter Roberson
Walter Roberson 2020년 2월 22일
sum(randi([0,1],1,32).*2.^-(0:31))
Or
randi([0,2^32-1])/2^32
Or you can use rnd() or related to tell rand to use the shr3cong generator, which has the required results.
Or you could rand() and throw away bits 33 to 52.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by