Darwinbots Forum

Code center => Darwinbots Program Source Code => Topic started by: Zelos on October 15, 2005, 11:18:21 AM

Title: Binary
Post by: Zelos on October 15, 2005, 11:18:21 AM
nums, you talk about in enzymes about using hexa for enzyme codes. the question is how big is one of those in bits? is it 4 bits? and is "1" 0001 in bits? and "2" 0010? and "F" 1111?
and is there a way to know what bit pattern a you represent?
Title: Binary
Post by: Numsgil on October 15, 2005, 12:21:58 PM
A hex code is 4 bits (2^4 = 16, so each digit in Hex has 16 possible values).  Thus each byte is represented by 2 hex codes.

You can convert numbers between hex, binary, and hexidecimal really easy, but I forget how at the moment.  I always just use the calculator that comes with windows.  In "scientific" mode it can operate as a converter between decimal, hex, and binary.
Title: Binary
Post by: Zelos on October 15, 2005, 12:40:13 PM
Nice, but what about letters? doesnt each letter represent a byte? so how do I convert a binary code/ hexa code into a letter as we know them?
Title: Binary
Post by: Numsgil on October 15, 2005, 12:43:19 PM
In hex:

A = 10 in decimal
B = 11 "
C = 12
D = 13
E = 14
F = 15
10 = 16
Title: Binary
Post by: Zelos on October 15, 2005, 12:47:17 PM
I know that, I got hexa on my calculator and my first program.
in the vb code of db how were you acctualy planning doing this kind of stuff? I mean making a code of letters/hexa into stuff the program can read?
Title: Binary
Post by: Numsgil on October 15, 2005, 12:57:36 PM
I would create an array of booleans to represent bits.  I've already done that for the new bit operators in the DNA for 2.4
Title: Binary
Post by: Zelos on October 15, 2005, 01:14:53 PM
hmmm, so true = 1 and false = 0?
interesting, but what about mixing them?
Title: Binary
Post by: Numsgil on October 15, 2005, 01:15:54 PM
How do you mean mixing?

Like reconstructing a decimal value based on the bits?  Or...
Title: Binary
Post by: Zelos on October 15, 2005, 01:29:26 PM
didnt you say that if we have a binary code like 1010 the program will mix it around so it becomes something like 0110 and then it begins readiing?
Title: Binary
Post by: Numsgil on October 15, 2005, 02:32:37 PM
Oh, yeah.  That's easy, you just XOR swap bits if you want to rearrange, or compliment the bit if you want to change it, etc.
Title: Binary
Post by: Griz on October 15, 2005, 02:48:35 PM
Quote
A hex code is 4 bits (2^4 = 16, so each digit in Hex has 16 possible values).  Thus each byte is represented by 2 hex codes.

You can convert numbers between hex, binary, and hexidecimal really easy, but I forget how at the moment.  I always just use the calculator that comes with windows.  In "scientific" mode it can operate as a converter between decimal, hex, and binary.
it's the same calculation regardless of base ...

using 4 digits for example:
--4--3--2--1
v4   v3   v2   v1

in decimal (base 10)
v(1-4) can be 0 to base-1 [or 0 - 9]
and the resulting value is an addition of:
v1 x base^0 = v1 x 10^0 = v1 x 1
v2 x base^1 = v2 x 10^1 = v2 x 10
v3 x base^2 = v3 x 10^2 = v3 x 100
v4 x base^1 = v4 x 10^3 = v4 x 1000
etc ... how ever many digits you want to go.

this is how we all learned to count.. or should have. ;)
 
in hexidecimal (base 16):  
--4--3--2--1
v4   v3   v2   v1
where v(1-4) can be 0 to F [0 - 15]
the value is an addition of:
v1 x base^0 = v1 x 16^0 = v1 x 1
v2 x base^1 = v2 x 16^1 = v2 x 16
v3 x base^2 = v3 x 16^2 = v3 x 256
v4 x base^1 = v4 x 16^3 = v4 x 4096

in binary (base 2):
where 8 bits are used to make up a byte
v(1-8) can be 0 or 1  
--8--7--6--5--4--3--2--1
v8   v7   v6   v5   v4   v3  v2   v1
the value is an addition of:
v1 x base^0 = v1 x 2^0 = v1 x 1
v2 x base^1 = v2 x 2^1 = v2 x 2
v3 x base^2 = v3 x 2^2 = v3 x 4
v4 x base^3 = v4 x 2^3 = v4 x 8
v5 x base^4 = v5 x 2^4 = v5 x 16
v6 x base^5 = v6 x 2^5 = v6 x 32
v7 x base^6 = v7 x 2^6 = v7 x 64
v8 x base^7 = v8 x 2^7 = v8 x 128

Note:
while in binary ...
it takes 8 digits to represent 0-255 (00000000 - 11111111)
in hex ...
it takes only 2 digits to represent 0-255 [00 to FF]
it's no mistake we use binary and hex in computers ...
as 2^8 = 16^2 = 256 and can be used to represent 0-255 ...
so we only need two placeholders instead of 8.

well ...
got carried away there ...
you guyz probable know all this and more.

I learned how to do all this by hand back when the
only calculator we had was a pencil and sliderule ...
and we geeks of those daze wore them slung from
our belts in leather holsters like a six-shooter ...
and the only computer ... one's own brain. ;)
and I just happen to love numbers ...
they make more sense then most people. :lol:

~griz~
Title: Binary
Post by: Zelos on October 15, 2005, 02:50:38 PM
I know how to change base, for crying out loud ive made a simple little program doing it. and im gonna show why 2^8 = 16^2 = 256
16=2^4
so 16^2=(2^4)^2=2^(2*4)=2^8
and voila its proven. But how can I be sure that (A^B )^C = A^(B*C)?
well, X^y=X times it self y times.
so let put numbers instant its easier:
(5^2)^3=5^2*5^2*5^2=5^(2+2+2)=5^(2*3)
but what about a^b*a^c=a^(b+c) then? lets take numers again its easier to see then:
5^2*5^3=(5*5)*(5*5*5)=5*5*5*5*5=5^5=5^(2+3)
and there we got it :D
now ur asking why did I do this? cause I wanted thats why
Title: Binary
Post by: Griz on October 15, 2005, 02:58:55 PM
Quote
I know how to change base, for crying out loud ive made a simple little program doing it.
that's fine ...
but perhaps not every member here does ...
so maybe it's not all about you! ;)
I only offer this up for those who may not know ...
or may not have explored it in detail ...
to any who might be interested.

as with anything I post here or elsewhere ...
twywaltr
(take what you want and leave the rest) :P

~griz~
Title: Binary
Post by: Zelos on October 15, 2005, 03:09:11 PM
oh sorry, though you were thinking on my then. if you wanna tell the rest thats okey
Title: Binary
Post by: Zelos on October 15, 2005, 03:25:47 PM
nums, you said a while ago you had a formula that is easier for the computer to tell the square root, could you tell me that formula?
Title: Binary
Post by: Numsgil on October 15, 2005, 04:46:23 PM
That's funny, I just went and tested it today!

Turns out the little bugger is actually slower than regular square root.  Which blows me away, because this function uses like 3 multiplications and not a whole lot else.

I'm going to go research some more, I'll post back here in a new thread if I find anything interesting.
Title: Binary
Post by: Numsgil on October 15, 2005, 05:02:10 PM
Ahaha, here's what I found out:

most compilers (including VB) use some art of the processor specifically built for square rooting.  Result?  Square rooting using sqr(number) is about as fast as you can get.

even doing 1 / sqr(number) is faster than the other ways available.
Probably isn't true on older machines though.
Title: Binary
Post by: Endy on October 15, 2005, 09:02:00 PM
Quote
I only offer this up for those who may not know ...
or may not have explored it in detail ...

I'll raise my hand for that one. Anything outside of decimal hurts my head.

I probably need to learn at least some binary, with the new operators out there I'm sure this will become important eventually.

The compliment feature ~ already looks like it'll be extremly useful to convert from zero to one (with use of abs) or vice versa, depending on what conditional you need.
Title: Binary
Post by: PurpleYouko on October 16, 2005, 12:53:39 PM
I have a database that stores numbers in base 64. It uses 0-9 and the entire alphabet in upper and lower case and a few other characters too. That was a bit freaky to program but it cut down the length of ID codes from about 12 digits to 4  :D
Title: Binary
Post by: Zelos on October 16, 2005, 01:23:48 PM
well, that help alot, with that you get 16777216 possible combinations