Hauptinhalt

Bit Set

Set specified bit of stored integer to one

  • Bit Set block

Libraries:
Simulink / Logic and Bit Operations
HDL Coder / Logic and Bit Operations

Description

The Bit Set block sets the specified bit of the stored integer to one. Scaling is ignored.

You can specify the bit to be set to one with the Index of bit parameter, where bit zero is the least significant bit.

Examples

expand all

This examples show how to use the Bit Set block to set the value of the specified bit index to 1.

A vector of constants 2.^[0 1 2 3 4] is represented in binary as [00001 00010 00100 01000 10000].

Open BitSetModel.slx and explore the Constant block and Bit Set block settings.

open_system('BitSetModel');

Simulate the model.

sim('BitSetModel');

With the index set to 2, the result is [00101 00110 00100 01100 10100], which is represented in decimal as [5 6 4 12 20] in the Display block.

Ports

The Bit Set block supports Simulink® integer, fixed-point, and Boolean data types. The block does not support true floating-point data types or enumerated data types.

Input

expand all

Input signal with the specified bit of the stored integer.

Data Types: int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point | bus

Output

expand all

Output signal with the specified bit set to 1.

Data Types: int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point | bus

Parameters

expand all

Index of bit where bit 0 is the least significant bit.

Programmatic Use

Block Parameter: iBit
Type: character vector
Values: scalar | vector
Default: '0'

Block Characteristics

Data Types

Booleana | fixed point | integer

Direct Feedthrough

yes

Multidimensional Signals

yes

Variable-Size Signals

no

Zero-Crossing Detection

no

a Bit operations are not recommended for use with Boolean signals.

Extended Capabilities

expand all

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

PLC Code Generation
Generate Structured Text code using Simulink® PLC Coder™.

Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.

Version History

Introduced before R2006a

expand all

See Also

| | (HDL Coder) | (HDL Coder)