我如何应用8位二进制值的补码? [英] How I Apply Complement For Binary Value Of 8 Bit Alternatively?

查看:158
本文介绍了我如何应用8位二进制值的补码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请使用bitset和bitget函数向我发送编码请发给我编码



例如:

29 = 00011101

从右到左适用第1,第3,第5,第7位

i得72 = 01001000



请给我发送编码

please send me the coding with out using bitset and bitget function please send me the coding

eg:
29=00011101
apply complement to 1st,3rd,5th,7th position from right to left
i got 72=01001000

please send me the coding

推荐答案

为什么你想在没有bitset或bitget函数的情况下这样做真的很奇怪。但是这里的算法是做同样的算法



0.将数字转换为位数组

1.使用数组迭代

1.1。每个奇数元素的newbit = 1- oldbit

2.将位数组转换为数字。





或者

在步骤1数组中使用它(0:1:结束)= 1 - 数组(0:1:结束);
Well it really odd why you want to do this without bitset or bitget function. But anway here is the algorithm to do the same

0. Convert the number to bit array
1. Iterate with the array
1.1. newbit= 1- oldbit for each odd elements
2. Convert the bit array to number.


or
use this in step 1 array(0:1:end) = 1 - array(0:1:end);


这篇关于我如何应用8位二进制值的补码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆