Jump to content


Photo

Introduction To Binary


  • Please log in to reply
23 replies to this topic

#1 Mike.Dailly

Mike.Dailly

    Evil YoYo Games Employee

  • Administrators
  • 5277 posts
  • Version:GM:Studio

Posted 25 April 2014 - 05:06 PM

I've finally finished writing my introduction to binary article. It should (in theory) introduce you to how binary works, show some basic maths operations, how to use binary flags, and some other of the cool little tricks you can do once you know this stuff. You can read it on our Techblog.

 

http://www.yoyogames.com/tech_blog/58

 

 

Enjoy!


  • 16

#2 NakedPaulToast

NakedPaulToast

    GM Studio/Mac/Win

  • GMC Member
  • 8808 posts
  • Version:GM:Studio

Posted 25 April 2014 - 05:36 PM

There are 10 kinds of people, those who understand binary, and those who don't.

 

If you don't understand the above statement, then you need to read Mike's Binary TechBlog.


  • 20

If the Bible truly is inspired by God, you would think that somebody as omnipotent and all-knowing would have known to get his message out using TCP instead of UDP.

 


#3 Lukan Spellweaver

Lukan Spellweaver

    Gay Wizard Freak & mcmonkey's plaything

  • GMC Member
  • 3704 posts
  • Version:GM:Studio

Posted 25 April 2014 - 06:09 PM

Thanks Mike! It's like you read my mind, I was just wanting to learn binary to make my save files a tad more secure!

I will definitely give this a read!

 

EDIT: I read the first few paragraphs, and I actually understood them! I'm not really in a calm learning environment right now, but I have bookmarked the page for later use. Thanks again! :D


Edited by LukanSpellweaver, 25 April 2014 - 06:20 PM.

  • 0

DeEuDARh.pngi1SR21Q.png

Find me on Itch.io | GameJolt | YouTube | Twitter | Facebook | Website | Ask.FM

 GMC Google Hangout | I liek monkehs

The GMC, here lies she. Kicked to the curb, with nary a word. She shall live on, though. Remain strong, bros.

Also: MIKE DAILLY TOLD ME TO UPDATE MY SIGNATURE


#4 grandhighgamer

grandhighgamer

    Village Idiot

  • GMC Member
  • 3876 posts
  • Version:GM:Studio

Posted 25 April 2014 - 08:04 PM

A pretty good article that goes nicely into depth about several useful concepts, although you make use of hexidecimal during it without any prior explaination, which would likely lead newcomers into going 'Huh? What the heck is $1F ?!'. That's kind of out of place in a beginners guide to decimal since there's been no explaination of both the basic overview of hexidecimal (if you need how to count in decimal explaining there's a large chance you don't know how to count in hexidecimal) and the use of hexidecimal in easily representing binary numbers.


  • 5

GHG WUZ ERE


#5 Mike.Dailly

Mike.Dailly

    Evil YoYo Games Employee

  • Administrators
  • 5277 posts
  • Version:GM:Studio

Posted 25 April 2014 - 08:12 PM

Very good point...I'll look to correct that.  Thanks.


  • 2

#6 Mnementh

Mnementh

    15151

  • GMC Elder
  • 6400 posts
  • Version:GM:Studio

Posted 25 April 2014 - 09:00 PM

Quick: what's -1 in binary?
 

Computers only multiply in 2s, and to do more it'll break a number apart, and then add all the results together.

Is this actually true? It seems reasonable enough. It would probably be useful to give an example like: 7*5 = (1 + 2 + 4) * 5 = 1 * 5 + 2 * 5 + 4 * 5 = 5 + 10 + 20 = 35.
 
But how does integral division by numbers that aren't powers of two work? It's definitely not by converting to floating point representation.

This will actually compile down to just "a & 11111111111111111111111111111010".

No it won't; it will compile to "a & 4294967290". I wonder whose phone number that is?

Edited by Mnementh, 25 April 2014 - 09:04 PM.

  • 0

#7 NakedPaulToast

NakedPaulToast

    GM Studio/Mac/Win

  • GMC Member
  • 8808 posts
  • Version:GM:Studio

Posted 25 April 2014 - 09:04 PM

Quick: what's -1 in binary?
 

 

Can't be answered without knowing the word size.


  • 3

If the Bible truly is inspired by God, you would think that somebody as omnipotent and all-knowing would have known to get his message out using TCP instead of UDP.

 


#8 Mike.Dailly

Mike.Dailly

    Evil YoYo Games Employee

  • Administrators
  • 5277 posts
  • Version:GM:Studio

Posted 25 April 2014 - 09:07 PM

-1 in 32bit is 1111111111111111111111111111111 (all bits set) Negative numbers are 2 complement. (for the record to negate, you do "xor -1" and increment it by 1)

 

Also means if you want to know if a number is negative, you just look at the top bit.  :)

 

Division is too complex, and would just confuse everyone.


Edited by Mike.Dailly, 25 April 2014 - 09:50 PM.

  • 0

#9 NakedPaulToast

NakedPaulToast

    GM Studio/Mac/Win

  • GMC Member
  • 8808 posts
  • Version:GM:Studio

Posted 25 April 2014 - 09:42 PM

The best way to think of negative number representation in binary is to picture a car odometer.

 

Imagine you bought a brand new car and the odometer read 0000000, now driving forward will 1 Mile will cause the odometer to read 0000001. But what if the odometer read 0000000 and you drove it bckwards 1 Mile. All the 0's would roll back 1 unit giving a reading of 9999999.

 

I'm unsure if modern cars with digital odometers roll backwards, but older cars with rotating number dials used to. My Source: Christine.


  • 0

If the Bible truly is inspired by God, you would think that somebody as omnipotent and all-knowing would have known to get his message out using TCP instead of UDP.

 


#10 Lonewolff

Lonewolff

    Permanent Resident

  • GMC Member
  • 3517 posts
  • Version:GM:Studio

Posted 25 April 2014 - 10:45 PM

 I'm unsure if modern cars with digital odometers roll backwards, but older cars with rotating number dials used to. My Source: Christine.


Didn't work in 'Ferris Buelers Day Off' :P
  • 1

#11 dmitry.nsk

dmitry.nsk

    GMC Member

  • GMC Member
  • 244 posts
  • Version:GM:Studio

Posted 27 April 2014 - 09:53 AM

BTW, why GML does not support binary records in expressions? like

x = mouse_x & 0b1111111111100000

sometimes very much doesn't suffice


  • 0

Forgive me for my bad English.pardon.gif If you notice an error in my messages, programs, etc., please send me a message about it.

assets.png


#12 zbox

zbox

    GMC Member

  • GMC Member
  • 2618 posts
  • Version:Unknown

Posted 27 April 2014 - 01:56 PM

Very very nice... I found personally that starting from a higher level (i.e using gamemaker) and then progressing down to lower levels as I gained more experience, I certainly was a bit stumped with exactly what binary was and how it was applicable learning about it that way, whereas the other approach, going from basics at low level to high, you'd be learning all this stuff first, which I think now that I know it is absolutely crucial. A good step towards breaching that sort of gap that is made by getting people to start learning in a highend environment.. which certainly is a lot faster to pick up but misses a few fine details :)

 

EDIT: Just read the first 2 paragraphs of the post, explained what I was getting at much more elegantly! :P


Edited by zbox, 27 April 2014 - 02:10 PM.

  • 0

#13 iceshield

iceshield

    GMC Member

  • GMC Member
  • 515 posts
  • Version:GM:Studio

Posted 27 April 2014 - 06:17 PM

Interesting article, very nice.

But you forgot to mention about signed bytes :) , so people will come with questions like , " and how do I write -1 in binary ?"

 

Answer (use one bit to sign - or +, notice that you will lose a value, max 127 min -128)

01111111 = +127
01111110 = +126
01111101 = +125
...
00000001 = +1
00000000 = 0
11111111 = -1
...
10000010 = -126
10000001 = -127
10000000 = -128

Edited by iceshield, 27 April 2014 - 06:22 PM.

  • 1

If you put comments in your code to understand it ... then you awful at writing code.


#14 ShadeSpeed

ShadeSpeed

    Procedural Generation King

  • GMC Member
  • 771 posts
  • Version:GM:Studio

Posted 28 April 2014 - 01:55 PM

 

Interesting article, very nice.

But you forgot to mention about signed bytes :) , so people will come with questions like , " and how do I write -1 in binary ?"

 

Answer (use one bit to sign - or +, notice that you will lose a value, max 127 min -128)

01111111 = +127
01111110 = +126
01111101 = +125
...
00000001 = +1
00000000 = 0
11111111 = -1
...
10000010 = -126
10000001 = -127
10000000 = -128

 

No values are lost here. It's just a different range of values.


  • 0

Marketplace Resources

 

code.png page.png video.png


#15 vampy09

vampy09

    GMC Member

  • GMC Member
  • 45 posts
  • Version:GM:Studio

Posted 01 May 2014 - 03:17 AM

Right now I'm trying to learn 6502 ASM, so this article is very helpful !

EDIT
I found a typo:

So where the is a value, there is always a value,...

Edited by vampy09, 01 May 2014 - 07:12 PM.

  • 0
The next best thing to knowing something, is knowing where to find it.

#16 Mike.Dailly

Mike.Dailly

    Evil YoYo Games Employee

  • Administrators
  • 5277 posts
  • Version:GM:Studio

Posted 01 May 2014 - 11:08 AM

Fixed - thanks.  Also removed HEX references, as it's never explained what HEX really is :)


  • 1

#17 Coffee

Coffee

    Light and Sweet

  • GMC Member
  • 2351 posts
  • Version:GM:Studio

Posted 08 May 2014 - 06:45 PM

Very interesting read which I'll have to come back to. Nice job.


  • 0

vmh.png Come Play Hungry Hungry Frogs!


#18 Schyler

Schyler

    Noskcirderf Derf

  • GMC Member
  • 2680 posts
  • Version:GM:Studio

Posted 08 May 2014 - 10:45 PM

The last operator we want to look at is EOR (Exclusive OR, sometimes called XOR)

* The last operator we want to look at is XOR (Exclusive OR, never called EOR) ...

 

NPT below: I bet you feel dumb that none of those actually mention "EOR" except Wikipedia.


Edited by Schyler, 17 May 2014 - 08:57 AM.

  • -1

#19 NakedPaulToast

NakedPaulToast

    GM Studio/Mac/Win

  • GMC Member
  • 8808 posts
  • Version:GM:Studio

Posted 08 May 2014 - 11:19 PM

 

The last operator we want to look at is EOR (Exclusive OR, sometimes called XOR)

* The last operator we want to look at is XOR (Exclusive OR, never called EOR) ...

 

2.8 million google hits disagree with you.

 

https://www.google.c..._sm=93&ie=UTF-8


Edited by NakedPaulToast, 09 May 2014 - 03:04 AM.

  • 0

If the Bible truly is inspired by God, you would think that somebody as omnipotent and all-knowing would have known to get his message out using TCP instead of UDP.

 


#20 ThePC007

ThePC007

    Chickenator

  • GMC Member
  • 1062 posts
  • Version:GM:Studio

Posted 10 May 2014 - 12:58 PM

There are 10 kinds of people, those who understand binary, and those who don't.

 

If you don't understand the above statement, then you need to read Mike's Binary TechBlog.

 

I already know that one, hehe. :)


  • 0

#21 Mike.Dailly

Mike.Dailly

    Evil YoYo Games Employee

  • Administrators
  • 5277 posts
  • Version:GM:Studio

Posted 10 May 2014 - 03:18 PM

 

The last operator we want to look at is EOR (Exclusive OR, sometimes called XOR)

* The last operator we want to look at is XOR (Exclusive OR, never called EOR) ...

 

It depends on the processor. Z80 uses XOR, 6502 uses EOR.  Both mean the same thing XOR is short for eXclusive OR, while EOR is short for Exclusive OR.

 

Z80

http://nemesis.lones...qd/opcodes.html

 

6502

http://www.masswerk....uction_set.html


  • 1

#22 FatalSleep

FatalSleep

    FatalSheep?

  • GMC Member
  • 3974 posts
  • Version:GM:Studio

Posted 10 May 2014 - 07:47 PM

Anyways, I've never seen XOR as EOR, although XOR sounds much better. Interesting read, already knew a bit of this,

but it was pretty cool to learn about how to do collisions using bit operations.


  • 0

#23 Brawl

Brawl

    Magnitude Games

  • GMC Member
  • 1299 posts
  • Version:GM:Studio

Posted 25 May 2014 - 09:37 PM

There are 10 kinds of people, those who understand binary, and those who don't.


And those who didn't expect this joke to be in base 3.

Anyway, great article Mike. Learning binary is a great thing to do to get a better understanding of how computing works in general, let alone improve your programming skills.
  • 1

#24 Mrpete

Mrpete

    GMC Member

  • GMC Member
  • 59 posts

Posted 02 June 2014 - 12:44 AM

Enjoyed reading this Mike.  Gives great history to binary manipulation for people who don't know. Though you altered the HEX section of your post.  I feel HEX is still needing a section for explanation(perhaps at a later time). As it simplifies things later for newcomers and gives history to why the changes between the two number bases are needed.


  • 1