Hi,
napisałem program, który zamienia dec na bin. Odwrócenie kolejności liczb zrealizowałem na stosie. Problem w tym, że otrzymuję niepoprawne dane wyjściowe. Dla podanego w kodzie n (n = 125) otrzymuję wynik w postaci 1011111.
// hh.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
template <class T>
class Stos {
enum{ssize = 100};
T s[ssize];
int index;
public:
Stos() : index(0) {
}
void push(T in) {
s[index++] = in;
}
T pop() {
return s[--index];
}
int size() {
return index;
}
};
int main() {
Stos<int> x;
int n = 125;
int r;
while(n > 0) {
r = n % 2;
n = n / 2;
x.push(r);
std::cout<<x.pop();
}
std::cin.get();
}
Będę wdzięczny za pomoc.
Pozdrawiam