Kingsoft pen question "Write a function to describe the binary representation of the given integer"

Source: Internet
Author: User

4. Write a function to describe the binary representation of a given integer.
For example, a given integer131In binary format10000011, The function is required to output the following results:

1: 2

0: 5

1: 1

It indicates that it starts with a decimal bit and contains 2, 5, and 1.

Refer to the previous question to determine the name, entry exit, and return value of the function, and implement the function



// Js. cpp: defines the entry point of the console application. // # Include "stdafx. H "# include <iostream> using namespace STD; void parseint (int n); int _ tmain (INT argc, _ tchar * argv []) {int N; cin> N; parseint (n); System ("pause"); Return 0;} void parseint (int n) {int CNT = 0; int temp =-1; for (INT I = 0; I <8; ++ I) {If (N & (1 <I) {If (temp <0) // The first time {temp = 1; ++ CNT;} else if (temp! = 1) // encounter different numbers {cout <"0:" <CNT <Endl; // print the result temp = 1; CNT = 1 ;} else {CNT ++ ;}} else {If (temp <0) {temp = 0; ++ CNT ;}else if (temp! = 0) {cout <"1:" <CNT <Endl; // print the result of the previous section temp = 0; CNT = 1 ;} else {CNT ++ ;}}cout <temp <':' <CNT <Endl ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.