How to convert a number in to hexa decimal in Simulink without using functions?

조회 수: 21 (최근 30일)
Hi everyone,
I am trying to convert a number in to hexa decimal in Simulink without using any functions. Is there any way that this can be done with existing Simulink block? or else can anyone suggest me what would be the best way to do it in Simulink?
Thanks in Advance
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 2월 24일
Integer or floating-point numbers? Signed or unsigned? Range of values?
There are techniques that are workable (if slightly tedious) for integers 0 to 255 that get more tiresome as you increase the range.
Heck, for small integers I would probably just use a pair of lookup tables.

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

채택된 답변

Samatha Aleti
Samatha Aleti 2020년 2월 24일
Hi,
You may use "MATLAB function block" in your SIMULINK model to convert a number into hexadecimal format using “dec2hex" function.
Refer the sample SIMULINK model attached.
  댓글 수: 6
Raja Vardhan Reddy Kothakapu
Raja Vardhan Reddy Kothakapu 2020년 2월 24일
@Walter Roberson Thanks for your reply. I have 8 individual bytes. I need to convert them in to hexa decimal and concatenate. So my values lies in between 0 and 255 and yes, I am looking for nibble, as you mentioned above and also could you tell me, how do you convert uint8 in to nibble? and which block are you using?
Walter Roberson
Walter Roberson 2020년 2월 24일
Use two math blocks. The first one is uint8(floor(double(x)/16)) . The second is uint8(mod(x, 16)) . You can do the same thing for each of the 8 bytes, and put the resulting signals into a block that puts them together into a vector of whatever order you want.
Math blocks can be optimized inline by the Simulink accelerator so this can be efficient.
If you have a vector of 8 bytes already then extracting the nibbles can be done in vectorized form. Then it just becomes a matter of splicing the two vectors together, which can be done by concatenation and reshape.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by