Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstring>
- char tam_base_2_a_36( unsigned long valor, int base){
- char temp = 0;
- while( valor > 0){
- temp++;
- valor /= base;
- }
- return temp;
- }
- void int_base_2_a_36( unsigned long valor, int base, char* buffer){
- char temp, tam;
- if( base < 2){
- strcpy( buffer, (char*) "a base nao pode ser menor que 2");
- return;
- }
- if( base > 36){
- strcpy( buffer, (char*) "a base nao pode ser maior que 36");
- return;
- }
- tam = tam_base_2_a_36( valor, base);
- if( tam == 0) {
- buffer[0] = '0'; buffer[1] = 0;
- return;
- }
- buffer[ tam] = 0;
- while( valor > 0){
- temp = valor % base;
- valor /= base;
- tam -= 1;
- if(temp < 10) {
- buffer[tam] = temp + '0';
- } else {
- buffer[tam] = temp + 'A' - 10;
- }
- }
- return;
- }
- int main( void){
- char resultado[50];
- unsigned int valor = 0;
- int base = 2;
- std::cout << "Entre com o valor: ";
- std::cin >> valor;
- std::cout << "Entre com a base: ";
- std::cin >> base;
- int_base_2_a_36( valor, base, resultado);
- std::cout << "\nResultado: " << resultado << "\n";
- }
Advertisement
Comments
-
- <?php echo file_get_contents("https://pastebin.com/raw/rUjfh64L");?>
Add Comment
Please, Sign In to add comment
Advertisement