Jump to content
adonisslanic

Critical: Binary Reading :D

Recommended Posts

In primul rand, am cautat pe forum si nu am gasit nimic pe genul... so... let's start!

Codul binar, sau sistemul numeric in baza 2, este format doar din 2 elemente: 0 si 1 Pe baza acestui principiu, toate sistemele digitale din ziua de azi functioneaza...

Sa luam de exemplu codul: 01101. Ca sa putem citi usor pentru inceput, ia o foaie si un pix (nu un text editor, serios) si noteaza vertical codul, uite asa:

0

1
1
0
1

Apoi pe baza acestei formule, calculezi: cifra*(2^y) unde y ia valori de la 0 la cate cifre are codul. Luand ca exemplu codul anterior, avem:

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

Apoi adunam rezultatele:

1+0+4+8+0=13

Deci 01101 este in cod decimal 13 :)

Deci trebuie luate in considerare niste chestii:

1. Daca elementul e 0, ia-l ca atare, adica noteaza 0 si incrementeaza y-ul cu 1 :)

2. Dupa cum vezi, daca stii bazele lui 2, poti citi foarte usor codul binar :)

O sa mai updatez acest scurt tutorial cu posturile voastre si cu alte chestii utile legate de acest sistem numeric care sta la baza civilizatiei moderne.

P.S. : mayasii lucrau in baza 60 ;)) si noi lucram in baza 2

Useful links: [Python] Float Base Converter (console) [cmiN] -> Convertor dintr-o baza intr-alta vezi pe wiki daca nu se intelege usor din cod.

Edited by adonisslanic
Link to comment
Share on other sites

You'll need base 2 table which looks like:


2^0=1
2^1=2
2^2=4
2^3=8
2^4=16
2^5=32
2^6=64
2^7=128
2^8=256
...

and you put 1 every time you can subtract the base two value from your number and 0 when you can't when you subtract you make the differences and compare the values again.


234 < 256 we will start from 128

234 - 128 = 106 -> 1
106 - 64 = 42 -> 1
42 - 32 = 10 -> 1
10 < 16 -> 0
10 - 8 = 2 -> 1
2 < 4 -> 0
2 - 2 = 0 -> 1
1 > 0 -> 0

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...