Binary conversion-c++

Source: Internet
Author: User

The boring history class has compiled a binary conversion software, the software is relatively single, only decimal to binary, octal, hexadecimal conversion.

With the convenience of C4droid, the APK is generated directly, Andro-all.

/** Copyright (c) 2014, Yantai University School of Computer * All right reserved.* Shao * file: demo.cpp* finish: December 16, 2014 * version number: v1.0*/#include <iostream    >using namespace std;//decimal number converted to binary number void swap_1 (int n) {if (n < 2) cout << N;        if (n >= 2) {swap_1 (N/2);    cout << n% 2;    }}//decimal number converted to octal number void swap_2 (int n) {if (N < 8) cout << N;        if (n >= 8) {swap_2 (N/8);    cout << n% 8;        }}//decimal number converted to hexadecimal number void swap_3 (int n) {switch (n) {case 10:cout << "A";    Break        Case 11:cout << "B";    Break        Case 12:cout << "C";    Break        Case 13:cout << "D";    Break        Case 14:cout << "E";    Break        Case 15:cout << "F";    Break    Default:cout << N;    }}void swap_4 (int n) {if (n <) swap_3 (n);        if (n >=) {swap_4 (N/16);    Swap_3 (n% 16); }}int MaiN () {int num,choice;    int a[100], n = 0, I;    cout << "1_ decimal → binary" << endl;    cout << "2_ decimal → octal" << endl;    cout << "3_ decimal → hex" << endl;    cout << "Please enter the function to select:";    CIN >> Choice;    cout << "Please enter a value to convert:";    CIN >> Num;        if (choice = = 1) {cout << num << "Convert to binary:";        Swap_1 (num);    cout << Endl;        } else if (choice = = 2) {cout << num << "Convert to octal:";        Swap_2 (num);    cout << Endl;        } else if (choice = = 3) {cout << num << "translates to 16 binary as:";        Swap_4 (num);    cout << Endl; }}

Computer-side display:



Android display: (Android4.4.4)



Next project, make a Visual basic-based conversion.

Wait for the wind to come.

@ Mayuko

Binary conversion-c++

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.