# C++ program to convert decimal number into binary

In this we are going to learn how to convert decimal number to binary.

### Program to convert decimal to binary in C++

```/*
program : Decimal to binary.
description : to convert decimal number between 0 to 255 to binary  */
# include <iostream>
#include <math.h>
using namespace std ;
int main()
{
unsigned short int x=0,b=128 ,z=0,a=8 ;
cout<<"please enter the number between 0 and 255 \n";
cin >> x;
if (x>255)
cout<<" out of range ";
else
{
cout << x <<" converted to binary number :" ;
while (a!=0)
{
z=x&b ;
if (z==128)
cout << "1" ;
else
cout << "0";
x=(x << 1);
a-- ;
}
}
cout<<"\n";
system("pause");
return 0 ;
}
```
{"ft_lang_label":"__label__en","ft_lang_prob":0.5153378,"math_prob":0.98939556,"size":2367,"snap":"2021-43-2021-49","text_gpt3_token_len":674,"char_repetition_ratio":0.22090563,"word_repetition_ratio":0.047916666,"special_character_ratio":0.35276723,"punctuation_ratio":0.06870229,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9989043,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-16T07:51:02Z\",\"WARC-Record-ID\":\"<urn:uuid:84f5866c-44d7-4217-8697-bb12cc1b098d>\",\"Content-Length\":\"56608\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:27ad022f-f779-4ad8-b1a3-166f6725e174>\",\"WARC-Concurrent-To\":\"<urn:uuid:cea0cf2e-ce4a-4276-9200-32f1a9569e2b>\",\"WARC-IP-Address\":\"92.205.3.251\",\"WARC-Target-URI\":\"http://www.codebind.com/cpp-tutorial/c-program-convert-decimal-number-binary/\",\"WARC-Payload-Digest\":\"sha1:MDHZUWSEC2CFP6CK6CRD6BDPAR6K3ZDT\",\"WARC-Block-Digest\":\"sha1:2UA3CO7WQ42ERVNM3NDDPUONUTJ7WF7R\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323584554.98_warc_CC-MAIN-20211016074500-20211016104500-00336.warc.gz\"}"}