필터 지우기
필터 지우기

can we write hexadecimal values in matlab too?

조회 수: 12 (최근 30일)
Imtiaz nabi
Imtiaz nabi 2022년 3월 4일
댓글: Walter Roberson 2022년 3월 5일
Hi there I want to write some hexadecimal values in matlab for example
// Add TOW-count message into HOW
if (iwrd==1)
sbfwrd |= ((tow&0x1FFFFUL)<<13);
// Compute checksum
sbfwrd |= (prevwrd<<30) & 0xC0000000UL; // 2 LSBs of the previous transmitted word
nib = ((iwrd==1)||(iwrd==9))?1:0; // Non-information bearing bits for word 2 and 10
chan->dwrd[iwrd] = computeChecksum(sbfwrd, nib);

채택된 답변

Walter Roberson
Walter Roberson 2022년 3월 4일
0x1FFFFu32
The C code is a bit weak in that it assumes unsigned long is 32 bits.
  댓글 수: 4
Imtiaz nabi
Imtiaz nabi 2022년 3월 5일
but when I try to store these in a variable it automatically converts into deciamal in another computer that is running a matlab 2019b why is my computer giving me an error?
Walter Roberson
Walter Roberson 2022년 3월 5일
Starting in R2019b, you can write hexadecimal and binary values as literals using an appropriate prefix as notation. For example, 0x2A is a literal that specifies 42—and MATLAB stores it as a number, not as text.
So the reason for the difference between the r2019b system and your R2017b system is that MATLAB was improved as of R2019b to support hexadecimal constants.
Which is why earlier I said "in your version" of MATLAB that hex2dec and sscanf were your available choices.

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by