int2bit
Convert integers to bits
Description
Examples
Convert Vector of Integers to Bits
Specify a row vector of integers.
X = [12 5]
X = 1×2
12 5
Specify for four column-wise bit elements for the converted output. Then, convert the integers to bits.
n = 4; Y = int2bit(X,n)
Y = 4×2
1 0
1 1
0 0
0 1
Convert Matrix of Integers to Bits
Specify a matrix of integers.
X = int8([10 6 14; 11 5 9])
X = 2x3 int8 matrix
10 6 14
11 5 9
Specify that the first bit in each set of four column-wise bit elements for the output is LSB. Then, convert the integers to bits.
n = 4; msbfirst = false; Y = int2bit(X,n,msbfirst)
Y = 8x3 int8 matrix
0 0 0
1 1 1
0 1 1
1 0 1
1 1 1
1 0 0
0 1 0
1 0 1
Convert Array of Integers to Bits
Specify an array of integers.
X = randi([0,9],4,3,2,'uint16')
X = 4x3x2 uint16 array
X(:,:,1) =
8 6 9
9 0 9
1 2 1
9 5 9
X(:,:,2) =
9 4 6
4 9 0
8 7 8
1 9 9
Specify for three column-wise bit elements for the converted output. Then, convert the integers to bits.
n = 3; Y = int2bit(X,n)
Y = 12x3x2 uint8 array
Y(:,:,1) =
0 1 0
0 1 0
0 0 1
0 0 0
0 0 0
1 0 1
0 0 0
0 1 0
1 0 1
0 1 0
0 0 0
1 1 1
Y(:,:,2) =
0 1 1
0 0 1
1 0 0
1 0 0
0 0 0
0 1 0
0 1 0
0 1 0
0 1 0
0 0 0
0 0 0
1 1 1
Input Arguments
X
— Integers
scalar | vector | matrix | 3-D array
Integers, specified as a scalar, vector, matrix, or 3-D array of nonnegative integer values.
Example: [10 2]
specifies an input row vector of size
1-by-2.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
n
— Number of bits for conversion
positive integer
The number of bits for conversion to bits, specified as a positive integer.
Data Types: double
msbfirst
— Specification of MSB first
true
or 1
| false
or 0
Output Arguments
Y
— Bit representation of input integers
column vector | matrix | 3-D array
Bit representation of input integers, returned as a column vector, matrix, or 3-D
array. Y
has the same dimensions as X
except
that the number of rows in Y
is n
times the
number of rows in X
. The output Y
consists of
n
least significant bits in the specified orientation. If
n
is less than the number of required bits to represent the
values in X
, then the output Y
consists of
n
least significant bits.
The data type of Y
depends on the data type of
X
.
If
X
is a floating-point data type, thenY
is a floating-point data type.If
X
is a built-in unsigned integer data type, thenY
is of data typeuint8
.If
X
is a built-in signed integer data type, thenY
is of data typeint8
.If
X
is of data typedouble
, thenY
is of data typedouble
withn
no larger than 53.If
X
is of data typesingle
, thenY
is of data typesingle
withn
no larger than 24.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
Input values must be less than 264 for code generation when the input data type is double.
Version History
Introduced in R2021b
Apri esempio
Si dispone di una versione modificata di questo esempio. Desideri aprire questo esempio con le tue modifiche?
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)