How to make a binary sequence bit with given key?

조회 수: 2 (최근 30일)
Pham Ngoc Thanh
Pham Ngoc Thanh 2013년 8월 22일
Hi I have a key (ex: key=1234;) how i create a binary sequence bit whose length is 1000 with this key?

채택된 답변

Walter Roberson
Walter Roberson 2013년 8월 22일
Convert the key to binary. repmat() that as many times as will fit in a vector of length 1000. Fill the remainder of the 1000 with binary 0's.
  댓글 수: 3
Pham Ngoc Thanh
Pham Ngoc Thanh 2013년 8월 23일
dear Walter Roberdon Thank for your help but now i have a proplem, please help me again
i have
key = 1234;
bit_sequence = dec2bin(key);
how i convert bit_sequence = 10011010010 to A = [1 0 0 1 1 0 1 0 0 1 0]
Walter Roberson
Walter Roberson 2013년 8월 23일
Do you mean Ӓ, capital A with two dots, Unicode position (decimal) 1234 ? Or do you mean just capital A ?
If you mean Ӓ, capital A with two dots then
vec = [1 0 0 1 1 0 1 0 0 1 0]; %you have the vector somehow
char(bin2dec(char('0' + vec)))
and the reverse would be
ch = char(1234); %you already have the character somehow
dec2bin(ch) - '0'

댓글을 달려면 로그인하십시오.

추가 답변 (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