Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- // int size adalah ukuran biner, oktal dan hexa
- // int n adalah bilangan
- void convert_from_decimal(int SIZE, int n) {
- int a[10], i;
- // membagi
- for(i=0; n>0; i++) {
- //mencari sisa hasil bagi
- a[i] = n % SIZE;
- // membagi
- n = n / SIZE;
- }
- // membalik array untuk ditampilkan
- for(i=i-1; i >= 0; i--) {
- // biner dan desimal hanya print bilangan
- if (a[i] < 10) {
- cout << a[i];
- // dari A-F hanya hexa
- } else if (a[i] == 10) {
- cout << 'A';
- } else if (a[i] == 11) {
- cout << 'B';
- } else if (a[i] == 12) {
- cout << 'C';
- } else if (a[i] == 13) {
- cout << 'D';
- } else if (a[i] == 14) {
- cout << 'E';
- } else if (a[i] == 15) {
- cout << 'F';
- }
- }
- cout << endl;
- }
- int main() {
- int n;
- cout << "Desimal: ";
- cin >> n;
- cout << "Biner: "; convert_from_decimal(2, n);
- cout << "Oktal: "; convert_from_decimal(8, n);
- cout << "Hexa: "; convert_from_decimal(16, n);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement