Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of bit-by-bit extraction and binary conversion about C++ read-in

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Today, I'm going to talk to you about how to solve the problem of bit-by-bit extraction and binary conversion of C++ readings. maybe many people don't know much about it. in order to make you understand better, the editor summed up the following. I hope you can get something from this article.

I will not write a specific question on this blog, but just sum up a typical problem-reading in numbers and taking them out bit by bit.

Take the number 12345, for example.

Yes, first of all, we need to take out a position. Take it out like this:

12345 take 12345

12345mm 5. / / in order to find the rules

So we have its position. Ten of you are like this:

12345 take 10 times 1234

1234404.

By the same token, 100:

12345ax 100mm 123

123 to 3.

So you can find out which one to take out is to divide the primitive number by the bit name of this bit, and then modulo 10.

Program:

# include#includeusing namespace std;int main () {int a [100]; int wei = 0; int num; cin > > num; while ((num/ (int) pow)! = 0) / the termination condition of the loop is that the number of digits of this number is less than the number of digits to be divided this time {a [wei] = (num/ (int) pow (10Magnewei)); / / according to the conclusion just reached, take out all of you and save them in the array. Wei++;}}

Then there is the problem of binary conversion. In fact, it is similar to the bit problem, except that after it is taken out, it has to be multiplied by the power of the corresponding bit.

Program:

Long long to10 (int jz,int num) / / function: convert the input number to decimal {long long result=0; int wei=0; while (num/ (int) pow (10jiawei)! = 0) / / take out the input number bit by bit {result+=pow (jz,wei) * ((int) (num/pow (10wei); / / multiply the position of the number by the corresponding power wei++ of the decimal system / / (num/1) / / (num/10) / / (num/100)} return result;}

After reading the above, do you have any further understanding of how to solve the problem of bit-by-bit and binary conversion in C++ reading? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report