Author Topic: Binary Tutorial  (Read 8618 times)

0 Members and 1 Guest are viewing this topic.

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Binary Tutorial
« on: May 24, 2005, 08:40:15 pm »
Bits
If you're in this forum, you probably know that each letter is 8 bits long. A bit is a single integer, 0 or 1, which is actually represented by an impulse of electricty for 1, or a lack thereof for 0, in your computers RAM. Now, how do we convert these impulses of electricty to a letter?

ASCII
All 256 characters have an ASCII value, 0 to 255. Each of the 256 integers has a binary representation too. Lets asume you've already converted your letter to Ascii.
Note, this can be done by using 'a' in the common syntax, or Asc("a") in VisualBasic, asuming you're working with the letter a.

Place Value
The 8 binary integers each have a value of their own. From left to right, these are 128, 64, 32, 16, 8, 4, 2, and 1. This may be confusing, so I'll provide an example. The number 10000000 has a value of 128, and 00100000 has a value of 32. How do we get up to 256? We need to set more of 0's to 1's.

Applying Binary
By now, you should have a pretty good idea of how binary works. Now lets apply it to some actual use. A null terminator, commonly used at the end of packets, is the ASCII character 0. To represent this in binary, we use 00000000. The character "a" has an ASCII value of 97. This is where the real fun begins.

I don't see X number for any place in binary
You're going to have to do some major subtraction here. We're working with "a", ASCII letter 97. Seeing as how 97 is under 128, we set the first bit to 0.
0XXXXXXX
Its under 64, so we set the second to 1.
01XXXXXX
Before we go any further, we need to subtract 64 from 97. We are left with 33. Seeing as how 33 is over 32, we'll set the next bit to a 1, and subtract 32.
011XXXXX
We're left with one, and we know thats not equal or bigger than anything but itself, so we don't need to check for the rest. We'll just set the last bit to a 1 and we're done.
01100001 = 97.

If anyone has any questions, feel free to ask.
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: Binary Tutorial
« Reply #1 on: May 24, 2005, 08:56:21 pm »
I'd hope no one here needs a tutorial on binary. ;)

Here's a general approach to ASCII to binary conversions (and visa-versa):
http://www.dark-wire.net/sidoh/?fuseaction=code.view&id=6

Offline Nate

  • Full Member
  • ***
  • Posts: 425
  • You all suck
    • View Profile
Re: Binary Tutorial
« Reply #2 on: May 24, 2005, 09:01:04 pm »
WTF since when is binary not a two headed canary?

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: Binary Tutorial
« Reply #3 on: May 24, 2005, 09:06:46 pm »
Quote
A bit is a single integer, 0 or 1, which is actually represented by an impulse of electricty for 1, or a lack thereof for 0
Actually, that's not usually the way it works. 0 and 1 are generally represented as differently charged signals (IE -5V for 0, +5V for 1).

Also, for practical purposes, you might want to mention that the increase of the binary variables is exponentail. For each succeeding bit, its an increased power of two (with the starting point being 0).
« Last Edit: May 25, 2005, 12:50:33 am by Sidoh »

Offline Mythix

  • The Dude
  • x86
  • Hero Member
  • *****
  • Posts: 1569
  • Victory
    • View Profile
    • Dark-Wire
Re: Binary Tutorial
« Reply #4 on: May 25, 2005, 03:14:16 am »
Comp Skills one, we were forced to deciper binary by head, and write out answers in binary onto paper, let me tell you, that was an awesome week of 1's and 0's
Philosophy, n. A route of many roads leading from nowhere to nothing.

- Ambrose Bierce


Offline Ergot

  • 吴立峰 ^_^ !
  • x86
  • Hero Member
  • *****
  • Posts: 3724
  • I steal bandwidth. p_o
    • View Profile
Re: Binary Tutorial
« Reply #5 on: May 25, 2005, 11:10:17 pm »
Sigh, I love adding in binary... It's so simple :/
Who gives a damn? I fuck sheep all the time.
And yes, male both ends.  There are a couple lesbians that need a two-ended dildo...My router just refuses to wear a strap-on.
(05:55:03) JoE ThE oDD: omfg good job i got a boner thinkin bout them chinese bitches
(17:54:15) Sidoh: I love cosmetology

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: Binary Tutorial
« Reply #6 on: May 26, 2005, 03:22:56 am »
Quote
Actually, that's not usually the way it works. 0 and 1 are generally represented as differently charged signals (IE -5V for 0, +5V for 1).
Oh, duh. I wasn't using my brain.

Lawl big time @ Miffix.
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline rabbit

  • x86
  • Hero Member
  • *****
  • Posts: 8092
  • I speak for the entire clan (except Joe)
    • View Profile
Re: Binary Tutorial
« Reply #7 on: May 27, 2005, 08:30:13 am »
0d is actually 001000000000b.
97d is 001011000001b

ASCII characters are noted by positive integer values, since binary is a numerical system, it has positive and negative values.  0000b preceeding a value means negative, and 0010b means positive.  Don't forget your signs!

Offline Joe

  • B&
  • Moderator
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: Binary Tutorial
« Reply #8 on: May 28, 2005, 02:16:11 am »
oh man..
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: Binary Tutorial
« Reply #9 on: May 28, 2005, 02:21:45 am »
0d is actually 001000000000b.
97d is 001011000001b

ASCII characters are noted by positive integer values, since binary is a numerical system, it has positive and negative values.  0000b preceeding a value means negative, and 0010b means positive.  Don't forget your signs!

Don't you mean succeeding? :)

Offline Nate

  • Full Member
  • ***
  • Posts: 425
  • You all suck
    • View Profile
Re: Binary Tutorial
« Reply #10 on: May 28, 2005, 11:18:43 am »
I think Binary is properly read Right to Left.

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: Binary Tutorial
« Reply #11 on: May 28, 2005, 01:30:18 pm »
I think Binary is properly read Right to Left.

*slaps head*

Ugg, no more posting for me at 2AM. -_-

Offline rabbit

  • x86
  • Hero Member
  • *****
  • Posts: 8092
  • I speak for the entire clan (except Joe)
    • View Profile
Re: Binary Tutorial
« Reply #12 on: May 29, 2005, 10:00:47 am »
Joe is wrong.  Binary is read left to right, but the 4 signing bits are always first, so the sign always preceedes the number.