poeschlorn
poeschlorn

Reputation: 12440

Simulink: Bit extraction from 1-Byte Hex

I'm relatively new to Simulink and I am looking for a possibility to extract 1-3 specific bits from one byte. As far as I know the input format (bin, dec, hex) of the constant is irrelevant for the following!? But how can I say that the constant "1234" is hex and not dec?

In my model I use the "Constant Block" as my source (will be parametrised by a MATLAB variable which comes from a m-file). A further processing with the "Extract Bits Block" causes an error on incompatible data types.

Can someone help me to deal with this issue?

Greets, poeschlorn

Upvotes: 0

Views: 5921

Answers (3)

Phil Goddard
Phil Goddard

Reputation: 10772

If you have the Communications Toolbox/Blockset then you can use the Integer to Bit Converter block to do a conversion to a vector of binary digits then just extract the "bits" that you want. The Bit to Integer Converter block will do the reverse transformation.

If you don't have the Communicatins Blockset then it wouldn't be hard to do a similar thing to this using a plain MATLAB Function block.

enter image description here

Upvotes: 0

poeschlorn
poeschlorn

Reputation: 12440

Maybe this is not the most elegant solution, but I converted my input to decimal and then created a BCD representation of it via OR and AND logic blocks for further use.

Upvotes: 1

Clement J.
Clement J.

Reputation: 3032

You should probably do the conversion hex->dec in your .m initialization file and use this value in Simulink.

Upvotes: 2

Related Questions