excel二进制移位运算_matlab里二进制数的移位运算的函数

本文介绍了MATLAB中处理二进制数的函数,包括转换和移位操作。BITSHIFT函数用于对二进制数进行左移和右移,涉及乘以2的幂次或除以2的绝对幂次。通过示例展示了如何重复左移一个无符号16位值直至非零位溢出。
摘要由CSDN通过智能技术生成

matlab里二进制数的移位运算的函数

intersect:集合交集

ismember :是否集合中元素

setdiff :集合差集

setxor :集合异或(不在交集中的元素)

union :两个集合的并

unique :返回向量作为一个集合所有元素(去掉相同元素)

dec2bin(x) 是把十进制整数x变换为二进制

bin2dec(y) 是把二进制数y变换为十进制数

base2dec('x',a) 是把a进制数x变化为十进制数

dec2base(y,a) 是把十进制数y变化为a进制数

移位,循环,与,反等操作函数:

BITAND——对二进制数进行与操作;

BITOR——对二进制数进行或操作;

BITXOR——对二进制数进行异或操作;

BITSHIFT——对二进制数进行移位操作。

BITSHIFT——对二进制数进行移位操作。

C = BITSHIFT(A,K) returns the value of A shifted by K bits. A must be

an unsigned integer or an array of unsigned integers. Shifting by K

is the same as multiplication by 2^K. Negative values of K are allowed

and this corresponds to shifting to the right, or dividing by 2^ABS(K)

and truncating to an integer. If the shift causes C to overflow

the number of bits in the unsigned integer class of A, then the

overflowing bits are dropped.

C = BITSHIFT(A,K,N) will cause bits overflowing N bits to be dropped.

N must be less than or equal to the length in

bits of the unsigned integer class of A, e.g., N&lt=32 for UINT32.

Instead of using BITSHIFT(A,K,8) or another power of 2 for N, consider

using BITSHIFT(UINT8(A),K) or the appropriate unsigned integer class

for A.

Example:

Repeatedly shift the bits of an unsigned 16 bit value to the left

until all the nonzero bits overflow. Track the progress in binary.

a = intmax('uint16');

disp(sprintf('Initial uint16 value %5d is %16s in binary', ...

a,dec2bin(a)))

for i = 1:16

a = bitshift(a,1);

disp(sprintf('Shifted uint16 value %5d is %16s in binary',...

a,dec2bin(a)))

end

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值