understanding binary

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

understanding binary

Post by shiznatix »

i need to know how to put a number into binary and read a number that is in binary. can anyone show me to a good tutorial on how this works?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

know personally, or the functions?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

huh? i have to understand binary for school. just like being able to put the number 50 into binary and being able to see the binary of 178 and putting it into the number. just a basic understanding of how binary would work.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

well.. let class begin:
  • Binary is a number system based twos. We count (normally) in base ten, as in our digits go from zero through ten, whereas binary's is only zero and one. Standard notation of binary is often done in groups of four. Just like our normal counting, the farther left a digit is, the more significance it has. Each place in binary multiplies the previous by two: one bit has two possibilities; two bits have four; three, eight; and so forth. A group of four bits are called a nibble. Two nibbles make a byte. Two bytes, a word. Two words, a double-word. Two double-words, a quad-word. 1024 bytes, a kilobyte.

    Now, lets look at some binary and some of those terms:

    Code: Select all

    a word
            high                 low          bytes
     high      low       high      low        nibbles
    +---------+---------+---------+---------+
    | 1 1 1 1 | 1 1     |         |         | 
    | 5 4 3 2 | 1 0 9 8 | 7 6 5 4 | 3 2 1 0 | bit number
    +---------+---------+---------+---------+
    | 0 0 0 0   0 0 0 0   0 0 0 0   1 0 1 0 | 10 (base 10), 0x0A (base 16, or hexidecimal)
    | 0 0 0 0   0 0 0 0   1 1 1 1   1 1 1 1 | 255 (base 10), 0xFF (base 16)
    +---------------------------------------+
    The zeroth (or least significant) bit is considered bit one most often, since we typically start counting from one.
    Now, to find out what a number would be in binary, simply find the highest power of two that falls underneath that value. Repeat this process on each successive value. Those are the bits you need to mark as ones. Lets take the decimal value of 10, for example. 2^4 = 16, so that's too high. 2^3 = 8, it fits, so we mark that as a one. We must now find the next power of two that fits the new result: 10 - 8 = 2. And 2^1 = 2, so that bit's marked. 2 - 2 = 0, so we don't have any more bits to mark! :)
Well that's the super basics.. I can go other addition and subtraction if you'd like later.



Wikipedia has [a] really nice article(s) on binary for further reading: http://en.wikipedia.org/wiki/Binary_numeral_system
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

The wikipedia explains everything fairly well..

Things to pay attention to:
- floating numbers conversion. (Fe: try to convert 0.1 decimal to binary)
- multiplication/division by 2. (In binary representation all you need to do is shift left or right)
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post by $var »

256 bits

128 64 32 16 4 2 1 0

so

01000100 = 68

00010000= 32
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

Yup, and convert back, you simply add up the amount of 1's in the proper places. For instance, "10" is 2, "110" is 6 (the first 1 is 4, second 1 is 2, 2+4=6), and so fourth.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

got it down, next question. now sorry but this is a very vague question but this is what was on the board. please remember that i am going to school at a non english speaking college so that is why its really hard to learn in class until i can fully understand the language.

it went somtin like this

Image

once again, sorry it looks real strange but if someone knows what that is and where I can learn it then please point me there. thanks

edit: whoa that looks bad, ill put a picture up in a second hold on
edit2: there
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

they seem like bit marks, but I have no idea how they are interacting with that equation, as the results don't make a lot of sense.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

discrete math perhaps...
btw, shiznatix, do you speak russian? There's a quite a bit of awesome math resources available on the internet I'm aware of, but I used to bookmark only russian ones...
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

Are you an English native-speaker at an Estonian college? I speak Russian too, but probably not well enough to decipher descrete math in it. :)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

No idea what that table means. It looks a lot like a "truth table". However, if that's true, then the table should look similar to this

Code: Select all

A B C   (-A || -B)  -(B & C)
T T T      F           F
T T F      F           T
T F T      T           T
(At least that's how every truth table I've seen is set up).

My guess is 'v' means false, though I don't know why there's a 'v' in the equation.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply