[Tutorial] An in-depth look at binary and binary operators.
#41

Wow,great tut
I learned lot from this xD
Reply
#42

Deserves a bump!
Pretty nice tutorial, learned more then i should have learned today o.O
Reply
#43

-solved-
Reply
#44

Nice topic, I just learned about it (scientific programming) at university.

Hexadecimal system isn't that hard, it's just another way to write bytes. Like anything on your computer...

Here's a table of hexidecimal code:
Код:
0000 -- 0
0001 -- 1
0010 -- 2
0011 -- 3
0100 -- 4
0101 -- 5
0110 -- 6
0111 -- 7
1000 -- 8
1001 -- 9
1010 -- a
1011 -- b
1100 -- c
1101 -- d
1110 -- e
1111 -- f
so
Код:
0100 0010 1100 1101 0001 1101 0000 1111
in binary would be
Код:
42cd1d0f
in hexadecimal system.

It's the same as calculating bits the way explained in the first post, but only with 4 bits (thus max is 1111 = 1 * 2^3 + 1 * 2^2 + 1 * 2^1 + 1 * 2^0 = 8+4+2+1=15) and where you replace 10 by a , 11 by b, etc.

This is a quite useful tutorial, but you need to have some knowledge and a good amount of interest in it before you'll be able to understand it.

But, I have a question. I didn't fully understand what my teacher was saying. We were talking about 64bit and 32bit - I understood that - but I didn't understand how the numbers are saved.

Basically, in 64bit, you've got:

1 bit for the sign = 0 for positive numbers, 1 for negative
11 bits for the exponents = didn't really understand that, knowing you've got...
...52 bits for the mantissa.

And later on, he said the last number of the exponent would be the cypher before the comma...how does the system recognise it's the 1 or 0 before the "." or if it is actually an exponent? =/ I'm making this hard for you

Oh and for those more interested in binary code: calculating with it is easy as hell - that's why it's genious.
If you want to add, just do like you would do with normal numbers.
Код:
   0101 // 5
   0111 // 7
+----------
   0212 // 2 is not a bit. That's why we move it to the left, like we do in decimal counting. 2 becomes 0 and we add a 1 to the digit on the left of it
   0220 // stil 2's
   0300 // zamg a 3. Remain a 1 and add a 1 to the digit on the left - like adding 11 in decimal
   1100 // = 12. Worked

So, a bit (inside joke) shorter:
  111
  0101
  0111
+------
  1100

This was a difficult example, so I'll take an easier one for my short method:
   1    // This is the one you get when you sum up the two ones on the right. 
 0010 // 2
 0010 // 2
+----
 0100 // 4
Btw, why did they ever use digits? Because it's easy & natural. First scripts were made in wood (no joke), it had a hole in it (1) or it didn't (0). Magnetic charge used later on: Positive (1) or negative (0). Fybernet: light (1) or not (0). Genious, but hard to understand. (I think you should always know why something "unnatural" was invented.
Reply
#45

Oh, i wasnt aware that this was bumped lol. Im planning on editing the article soon. At the moment people are still having trouble understanding binary in general, and also when to use it. This is completely my fault, you can tell that some parts were extremely rushed and added in as an after thought. I definitely WILL fix this, the only problem is WHEN though. I have a lot of things im juggling at the moment (Another tutorial, an application, and a GM). Since this was bumped i might throw everything on the back burner, as im truly unhappy with this tutorial .

Im planning to completely rewrite the operator section (this was the most rushed area- at that point i was just itching to release it already), write a section covering when to use binary/some examples, do some general cleaning, and include the constant symbolic symbol "0b" in the article/examples.


@IKKE - I cant really understand what it is your asking me, sorry lol. Thanks for explaining HEX and stuff to the users though . I actually wrote a HEX article on the wiki, but it was just a template for this article to be honest, it definitely needs to be expanded. Here it is though in-case anyone wants to read/mod it: https://sampwiki.blast.hk/wiki/Hex
Reply
#46

Nice tutorial.
Reply
#47

Well, I was asking if you know something about general bits - not only those used in PAWN. I am learning about 64bit at university, but it wasn't clear for me at all, and it seems like you know a lot from it.

So we learned that, for doubles (64bits = 8 bytes for one rational = not complex number), the first bit returns whether it's positive or negative (same as in PAWN), the next 11 are the "exponents" and the other 52 are part of the "mantissa". I understand how the first number works, it's quite easy, but what about the other 11+52? Am I right if the first 11 are the same as in PAWN, the natural powers of 2?

So just 00000100001 would be 2^5 + 2^0 = 33?

But then that mantissa...no clue what it is, but it's about the decimal numbers (everything behind the comma). I just don't get how they define a rational number using those bits.

What I'm currently thinking about, is that the last bit of the 52 is 2^-1, the one but last 2^-2 and so on...am I right?

EDIT: I tried changing the hexadecimal wiki page (adding parts of my post referring to bits), but it says I need to log in. When I click on "Create Account", it refers me to the login page, and no single button "Create account" anywhere.
Reply
#48

Quote:
Originally Posted by IKKE
Посмотреть сообщение
Well, I was asking if you know something about general bits - not only those used in PAWN. I am learning about 64bit at university, but it wasn't clear for me at all, and it seems like you know a lot from it.

So we learned that, for doubles (64bits = 8 bytes for one rational = not complex number), the first bit returns whether it's positive or negative (same as in PAWN), the next 11 are the "exponents" and the other 52 are part of the "mantissa". I understand how the first number works, it's quite easy, but what about the other 11+52? Am I right if the first 11 are the same as in PAWN, the natural powers of 2?

So just 00000100001 would be 2^5 + 2^0 = 33?

But then that mantissa...no clue what it is, but it's about the decimal numbers (everything behind the comma). I just don't get how they define a rational number using those bits.

What I'm currently thinking about, is that the last bit of the 52 is 2^-1, the one but last 2^-2 and so on...am I right?

EDIT: I tried changing the hexadecimal wiki page (adding parts of my post referring to bits), but it says I need to log in. When I click on "Create Account", it refers me to the login page, and no single button "Create account" anywhere.
To be completely honest, im just as lost as you are at the moment. I've never really looked into how floats are represented before your comment (im STILL reading trying to make sense of it all). I'll have to keep reading for a while and get back to you with an answer when i make sense of everything! Hopefully it wont take to long to clear up the confusion (most of mine is coming from converting- i just get bad data :\ lol).

+Rep for making me go out and learn something new. I definitely will be adding a section for floating point representation when i can wrap my head around it. Once you get passed the basics, this becomes a really confusing topic lol.


Edit: Yeah registration for the wiki is closed, sorry . Why do you want to add bit related content to a hex explanation though? You should probably use decimal for explaining instead. Image if i tried to use hex to explain binary in this tutorial- its just gonna confused people who dont know the system and would be a mess lol.
Reply
#49

I've always wanted to know how floats are represented, I figured the more decimals used the larger the variable, or something...
Anyway, Can't wait for the update so I can learn too
Reply
#50

I know this is old thread but I must say: THANK YOUUUUUUUU!
Finally I understand for what use is ^, &, |, ~ >>, <<, >>>, <<< thank you man!
Reply
#51

Quote:
Originally Posted by Y_Less
View Post
That wasn't discovered by Slice, just happens to have been documented there. It has been documented before that too and is a method in use in other languages since long before SA:MP came out. It's actually a natively supported feature in C in the form of bit fields:

http://en.wikipedia.org/wiki/Bit_field
I used "discovered" very loosely, as I couldn't seem to find the word I was looking for (e.g. "documented"), but yes that's obviously true.
Reply
#52

Good guy, helped me a lot!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)