日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

在C ++中将十进制转换为二进制

發(fā)布時間:2024/3/26 编程问答 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 在C ++中将十进制转换为二进制 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Here you will get program to convert a number from decimal to binary in C++. 在這里,您將獲得在C ++中將數(shù)字從十進制轉(zhuǎn)換為二進制的程序。 How to convert decimal number to binary? 如何將十進制數(shù)轉(zhuǎn)換為二進制?
  • Divide the number by 2 and save the remainder somewhere.

    將數(shù)字除以2,然后將其余部分保存在某處。

  • Divide the quotient with 2 again and save the remainder somewhere.

    再次將商除以2,并將余數(shù)保存到某處。

  • Repeat the process until 1 is left as quotient.

    重復(fù)該過程,直到將1保留為商。

  • Now write the remainders in reverse order.

    現(xiàn)在,以相反的順序?qū)懹鄶?shù)。

This program can only convert non decimal numbers. 該程序只能轉(zhuǎn)換非十進制數(shù)字。 Convert Binary to Decimal in C++在C ++中將二進制轉(zhuǎn)換為十進制

C ++中的十進制到二進制程序 (Program for Decimal to Binary in C++)

#include<iostream>using namespace std;int main() {int d,n,i,j,a[50];cout<<"Enter a number:";cin>>n;cout<<"\nThe binary conversion of "<<n<<" is 1";for(i=1;n!=1;++i){d=n%2;a[i]=d;n=n/2;}for(j=i-1;j>0;--j)cout<<a[j];return 0; } Output輸出量 Enter a number:5輸入數(shù)字:5 The binary conversion of 5 is 1015的二進制轉(zhuǎn)換為101

翻譯自: https://www.thecrazyprogrammer.com/2011/03/c-program-to-convert-decimal-number-to-2.html

總結(jié)

以上是生活随笔為你收集整理的在C ++中将十进制转换为二进制的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。