Conversão de Decimal para Binário
Publicado por marlon luis petry 31/05/2005
[ Hits: 30.901 ]
Homepage: http://petryx.blogrs.com.br
Este algoritmo converte um número decimal para um número binário através de um pilha dinâmica.
/****************************************************************************** **Author = Marlon Petry **e-mail = marlonpetry@gmail.com **Date = 29/05/2005 **Description: Decimal to binary with queue dynamical ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ******************************************************************************/ #include <stdio.h> typedef struct queue { int value; struct queue *prev,*next; }q; q *topo = NULL,*base = NULL; void push(int value) { q *aux; if(topo == NULL) { base = (q *) malloc(sizeof(q)); base->value = value; base->next = NULL; base->prev = NULL; topo = base; } else { aux = (q *) malloc(sizeof(q)); aux->value = value; aux->prev = topo; aux->next = NULL; topo->next = aux; topo = aux; } } int pop() { int value; if(topo == NULL) return -1; else { value= topo->value; topo = topo->prev; } return value; } void convertDecBin(int dec) { int r; while(dec != 0) { r = dec%2; push(r); dec = dec/2; } } void show() { int flag = 0,b; printf("\nValue Binary is "); while(flag != 1) { b = pop(); if(b == -1) flag = 1; else printf("%d",b); } } main() { int dec; int ch; do { printf("Inform value DECIMAL\n"); scanf("%d",&dec); convertDecBin(dec); show(); puts("\n-1 for finish"); scanf("%d",&ch); }while(ch != -1); }
Estrutura de dados: Lista dinâmica duplamente encadeada
Manipulação de um vetor de registros
Como gerar qualquer emoji ou símbolo unicode a partir do seu teclado
Instalar e Configurar o Slackware Linux em 2025
Como configurar os repositórios do apt no Debian 12 em 2025
Passkeys: A Evolução da Autenticação Digital
Instalação de distro Linux em computadores, netbooks, etc, em rede com o Clonezilla
Muitas dificuldades ao instalar distro Linux em Notebook Sony Vaio PCG-6131L (VPCEA24FM)
Slackpkg+ (Slackpkg Plus) está de volta!
Como dividir duas janelas igualmente e lado-a-lado na sua tela
Configurando o Conky para iniciar corretamente no sistema
3 configurações básicas que podem melhorar muito a sua edição pelo editor nano
Erro de segmentação «Segmentation fault (core dumped)» ao retornar obj... (4)
Não Consigo instalar o cli-visualizer no Ubuntu 24.04 (2)
compilação samba 4.22 rock linux 9.5 (1)
Posso instalar usar o grub sem ter linux instalado, para iniciar o win... (1)
Ocomon 6.0.1 - Problemas ao editar configurações estendidas (4)