Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- void dec_to_bin(int liczba)
- {
- int i=0,tab[31];
- while(liczba)
- {
- tab[i++]=liczba%16;
- liczba/=16;
- }
- for(int j=i-1; j>=0; j--)
- {
- if(tab[j] > 9)
- cout << static_cast<char>(tab[j] + 55);
- // przykładowo: "cyfra" A ma wartość 10, natomiast litera A w systemie ASCII ma numer 65. Oznacza to, że musimy dodać 55, aby zrobić konwersję
- else
- cout << tab[j];
- }
- }
- int main()
- {
- int liczba;
- cout<<"Podaj liczbę: ";
- cin>>liczba;
- dec_to_bin(liczba);
- cout<<endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment