matlab二进制转符号,在MATLAB中无符号整型转二进制

bitget

Bit at specified position

Syntax

C = bitget(A, bit)

Description

C = bitget(A, bit) returns

the value of the bit at

position bit in A.

Operand A must be an

unsigned integer, a double, or an array containing unsigned

integers, doubles or both.

The bit input

must be a number between 1 and the number of bits in the unsigned

integer class

of A (e.g., 32 for

the uint32 class).

The output of bitget is

independent of the endian settings of the computer you are

using.

Examples

Example 1 — Binary Conversion

The dec2bin function

converts decimal numbers to binary. However, you can also use

the bitget function

to show the binary representation of a decimal number. Just test

successive bits from most to least significant:

disp(dec2bin(13)) 1101 C = bitget(uint8(13), 4:-1:1) C = 1 1 0 1

Example 2 — Binary Compare

Prove that intmax sets

all the bits to 1:

a = intmax('uint8'); if all(bitget(a, 1:8)) disp('All the bits have value 1.') end All the bits have value 1.

Example 3 — Vector and Array Operations

Get the value of the second most significant bit of the number

sequence 5 through 75, counting by tens:

bitget(5:10:75, [2 3 4 5 5 5 6 7]) ans = 0 1 1 0 0 1 0 1

Do the same, but using 2-by-4 matrices:

bitget([5 15 25 35; 45 55 65 75], ... [2 3 4 5; 5 5 6 7]) ans = 0 1 1 0 0 1 0 1

See Also

bitand, bitcmp, bitmax, bitor, bitset,bitshift,bitxor

> c =

bitget(2,5:-1:1)

c =

0

0  0  1

0

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

dec2bin

Convert decimal to binary number in string

Syntax

str

= dec2bin(d)

str = dec2bin(d,n)

Description

returns the

str

= dec2bin(d) binary

representation of d as a

string. d must be a nonnegative

integer smaller than 2^52.

str

= dec2bin(d,n) produces

a binary representation with at

least n bits.

The output of dec2bin is independent of

the endian settings of the computer you are using.

Examples

Decimal 23 converts to binary 010111:

dec2bin(23) ans = 10111

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值