sábado, marzo 26, 2005

Conversión Decimal a Binario

Primero necesitamos saber que es un numero binario.

¿Que es un numero Binario?

Un verdadero número binario es una secuencia de dígitos binarios, como 0001010 ó 1001001. Sólo se usan 0s y 1s. El valor de los números en sí (o y 1) no determina el valor del número binario; lo que suma es el valor de los lugares. Cada lugar tiene un valor determinado. El primer lugar de la derecha de un dígito vale 1, el segundo lugar vale 2, el tercer lugar vale 4 y así sucesivamente. El valor de cada lugar se duplica a medida que se avanza hacia la izquierda de los números del sistema decimal 1 a 20.


Existen dos formas comunes de conertir un decimal a binario :

a) Suma de potencia de 2

Hacemos una tabla como la de Estrcuturas Abstractas de Datos en binario.

2^n (Dos a la n potencia)

Siempre empezaremos con el 0 (cero) que sera el primero de derecha a izquierda, el siguiente sera dos, quedaria algo asi:

2 1

Si añadimos el siguiente numero que es 4 quedaria:

4 2 1

y asi sucesivamente hasta llegar a un numero x, que sepamos que supera nuestro numero, por ejemplo el 10.

2^0 = 1
2^1 = 2
2^2 = 4
2^3 = 8


8 4 2 1

Sabemos que si sumamos todos los resultados da mas de 50.
Entonces tenemos que hacer una combinacion de esto para que den 50 exactos, y esto seria:

8+2 = 10

Al convertirlo a un numero Binario, se dice esta formado por 0 y 1s, para hacerlo seria asi:

Sabemos que NO ocupa el 1 para que la suma sea 10 entonces le ponemos un 0
Sabemos que SI ocupa el 2 para que la suma sea 10 entonces le ponemos un 1
Sabemos que NO ocupa el 4 para que la suma sea 10 entonces le ponemos un 0
Sabemos que SI ocupa el 8 para que la suma sea 10 entonces le ponemos un 1


Si ponemos atención sabemos que ya hemos completado el 10, entonces para ordenarlos quedaria:

Primero el del numero 8 (que es 1), luego el del 4 (que es 0), luego 2 (que es 1) y por ultimo el 1 (que es 0), y queda asi :

1010

8+0+2+0 =10


Esto quedaria representado
10 = 1010


Si queremos el 50 :
Ya sabemos que tenemos que sacar los numeros de 2^n

32 16 8 4 2 1

Sabemos que pasan sumando 50, ahora buscamos la combinacion:

32+16+2 = 50

Ahora sustituimos 0 en los numeros que no ocupamos y 1s en los que si.

110010

32+16+0+0+2+0 = 50

Y queda representado :

50 = 110010



Con un poco de practica se pueden comer muchos pasos y hacerlo mas rapido.

b)Por división repetida entre dos

Se divide el número repetidamente entre 2 y conservando los residuos hasta que se obtenga un cociente 0, el primer residuo es el LSB (Bit menos significante) y el último es el MSB (Bit mas significante).

Ejemplo:

10


10/2 = 05 con residuo 0 <--- LSB
05/2 = 02 con residuo 1
02/2 = 01 con residuo 0
01/2 = 00 con residuo 1 <--- MSB

Al momento de ordenarlo sera primero el MSB, que en este caso es 1, despues el anterior que es 0, y asi hasta llegar al LSB que este caso es 0. Quedaria asi:

1010


Ahora veamos con otro numero:

50/2 = 25 residuo 0 <--- LSB
25/2 = 12 residuo 1
12/2 = 06 residuo 0
06/2 = 03 residuo 0
03/2 = 01 residuo 1
01/2 = 00 residuo 1 <--- MSB

Los ordenamos del MSB al LSB y quedaria de la siguiente forma :

110010

El siguiente programa transforma de Binario a Decimal :

Nombre: Binario a Decimal
Extensión : .C

/* Programa sacado del rincondelc */
#include
#include
#define VAL_MIN 0
#define VAL_MAX 1111
int es_binario(int num);
int main(void){
int numero = 0;
printf("Introduce un numero binario:");
scanf("%d", &numero);
if (es_binario(numero))
printf("\nEl numero %d es binario\n", numero);
else
printf("\nEl numero %d no es binario\n", numero);
return EXIT_SUCCESS; } int es_binario(int num){
if ((num <> VAL_MAX)) return 0;
do {
if ((num%10 != 0) && (num%10 != 1))
return 0; }
while ((num /= 10) > 0);
return 1;
}


Y este orto es para Convertir de Decimal a Binario: [Link]
Es un .zip donde esta en varios lenguajes la conversión. (Página donde explica el autor [link])

12 Comentarios:

At 5:40 p.m., Anonymous Anónimo said...

whoah this blog is wonderful i really like reading your posts.
Keep up the good work! You recognize, lots of people are looking around for this info,
you could aid them greatly.

Also visit my website; comment devenir riche

 
At 9:15 p.m., Anonymous Anónimo said...

Pretty component of content. I just stumbled upon your website and in accession capital to claim that I get actually loved account your blog
posts. Anyway I will be subscribing for your feeds and even I success you
access consistently quickly.

My web page - devis porte fenetre pvc

 
At 3:58 a.m., Anonymous Anónimo said...

It's actually a nice and helpful piece of information. I am glad that you shared this helpful information with us. Please keep us informed like this. Thanks for sharing.

Feel free to surf to my webpage - ressort pour porte de garage basculante

 
At 8:38 a.m., Anonymous Anónimo said...

Hey this is kind of of off topic but I was wanting to know if blogs use WYSIWYG editors or
if you have to manually code with HTML. I'm starting a blog soon but have no coding know-how so I wanted to get advice from someone with experience. Any help would be enormously appreciated!

My website; lame de terrasse en bambou

 
At 3:15 a.m., Anonymous Anónimo said...

Hey! I just wanted to ask if you ever have any trouble with hackers?

My last blog (wordpress) was hacked and I ended up losing
months of hard work due to no data backup. Do you have any methods to protect against hackers?


Feel free to surf to my page ... monter une porte de garage basculante

 
At 4:06 a.m., Anonymous Anónimo said...

Hello There. I discovered your blog the use of msn.
That is a really smartly written article. I'll make sure to bookmark it and come back to learn more of your useful info. Thanks for the post. I'll certainly comeback.


Have a look at my site parquet contrecollé pas cher

 
At 1:44 p.m., Anonymous Anónimo said...

It is appropriate time to make some plans for the future and it is time to be happy.
I've learn this put up and if I may just I wish to counsel you some attention-grabbing things or advice. Maybe you can write subsequent articles referring to this article. I want to learn more issues about it!

my website: devis en ligne fenetre pvc

 
At 3:51 p.m., Anonymous Anónimo said...

Does your blog have a contact page? I'm having trouble locating it but, I'd like to shoot
you an email. I've got some suggestions for your blog you might be interested in hearing. Either way, great site and I look forward to seeing it develop over time.

My weblog: plombier de paris

 
At 4:37 p.m., Anonymous Anónimo said...

Ϲurrentlу it ѕοunds like Wοгdpress іs the bеst blоgging platform out there right now.

(from whаt I've read) Is that what you are using on your blog?

Here is my blog :: Author's eхteгnal homе pаge.
..

 
At 7:54 p.m., Anonymous Anónimo said...

Pleаse lеt me knοω if yοu're looking for a author for your site. You have some really good posts and I feel I would be a good asset. If you ever want to take some of the load off, I'd absolutely lovе
to write some articles for уour blog in exchange
foг a lіnk back tο mine. Ρlease shoot me аn еmail if
interested. Rеgards!

My homepage; pose du parquet

 
At 9:09 p.m., Anonymous Anónimo said...

I really love your blog.. Excellent colors & theme.
Did you create this website yourself? Please reply back as I'm trying to create my own site and would like to know where you got this from or what the theme is called. Cheers!

Feel free to surf to my webpage :: volet roulant pas cher

 
At 9:14 p.m., Anonymous Anónimo said...

Very nice post. I just stumbled upon your blog and wished to say that I have truly enjoyed browsing your blog
posts. In any case I will be subscribing to your feed and I hope you write
again very soon!

my web page: lame de terrasse meleze

 

Publicar un comentario

<< Home