PDA

View Full Version : Math Question, really....



$cirisme
September 9th 2003, 03:24 PM
I've always wondered what ORs, XORs, etc are. What are these things in my programming books that I do not understand?

Like, what do these: >>> & <<< do?

I need real help, they look really cool. Soc & Em7 would probably know...

Oh BTW, I just realized what the bitwise operators do... YAY for me!

:wink:

themuzicman
September 9th 2003, 03:32 PM
OR and XOR are logical operators, which computers use on 0 and 1.

0 is false, 1 is true.

OR, then, says that if either is true, then the result is true, thus the table:

---0--1---
0--0--1--
1--1--1--
----------

Thus if you have 0 or 0, the result is zero, but 1 or 0, 0 or 1, and 1 or 1 result in 1.

XOR, on the other hand, says that if there is ONE true and ONE false the result is true. Thus:

--0---1--
0-0---1--
1-1---0--

Thus, 0 xor 0 is false, but so is 1 xor 1. Only 0 xor 1 and 1 xor 0 are true.


As for >>> and <<< I assume that those are bit shifters, but I'm not really sure.

Michael

$cirisme
September 9th 2003, 03:44 PM
OR, then, says that if either is true, then the result is true, thus the table:

Perhaps I wasn't clear, but I was talking about inclusive-or... or maybe they are the same? :huh:

In the SHA1 RFC, it says this:


a. Bitwise logical word operations

X AND Y = bitwise logical "and" of X and Y.

X OR Y = bitwise logical "inclusive-or" of X and Y.

X XOR Y = bitwise logical "exclusive-or" of X and Y.

NOT X = bitwise logical "complement" of X.

Example:

01101100101110011101001001111011
XOR 01100101110000010110100110110111
--------------------------------
= 00001001011110001011101111001100

Which is what I don't understand... how can a conditional be used to affect output... unless you save the result as true/false(1/0) in building a new string. :shrug:

Em7add11
September 9th 2003, 03:47 PM
XOR is short for "exclusive or"

That means one or the other has to be true, but not both.

So:

A = False and B = False returns False
A = True and B = False returns True
A = False and B = True returns True
A = True and B = True returns False

$cirisme
September 9th 2003, 03:50 PM
Thanks for the answers on XOR, guys.

-cir, hopelessly lost :dufus:

Em7add11
September 9th 2003, 03:50 PM
01101100101110011101001001111011
XOR
01100101110000010110100110110111
--------------------------------
00001001011110001011101111001100


Note that when corresponding positions in each number are both 1's or 0's, it returns a 0. But if one position holds a 1 and the other a 0, it returns a 1.

themuzicman
September 9th 2003, 03:50 PM
Yes, that's exactly it. You line up all the 1s and 0s, and evaluate downward, like you were adding. So:


1100 XOR 0101 looks like this:

1100
0101
-------
1001

And then you put the new string in another memory location.

If you want to get down to silicone tacks, the CPU has various registers (32 or 64 bit), and they evaluate those bits based on AND, OR, XOR and NOT, and put the output in another register, where another process picks that register up and does something with it, either evaluating it, or directing it to a memory location.

(FYI, congratulations, you're as close to the physical layer of a CPU as most people get)

So in our example above, register A (in a 4 bit machine) would have 1100, and register B would have 0101, and the CPU would pull register A and register B, execute the function (XOR), and put the output (1001) in register C.

(Now, in CICS, or complex instruction computing set, there are a lot more functions than just AND, OR, XOR, and NOT, but even these are reduced at some level to these function.)

Is that clearer?

Michael

Em7add11
September 9th 2003, 03:52 PM
Muz, have you studied assembly language by any chance?

Warcraft3
September 9th 2003, 03:53 PM
Today @ 03:24 PM post located here (http://www.theologyweb.com/forum/showthread.php?s=&postid=206914#post206914)
cirisme:

I've always wondered what ORs, XORs, etc are. What are these things in my programming books that I do not understand?

Like, what do these: &gt;&gt;&gt; &amp; &lt;&lt;&lt; do?

I need real help, they look really cool. Soc &amp; Em7 would probably know...

Oh BTW, I just realized what the bitwise operators do... YAY for me!

:wink:

OR and XOR are logical operators. What they basically do is give you an output of TRUE or FALSE based on the input.

Lets use a two bit input (I shall label the two inputs 'A' and 'B' )with a one bit output(I shall label the output as 'C'). In the output let '1'=TRUE and '0'=FALSE.
------------------------------------------------------------------------------------
The OR operator
If either input A OR B is a '1', then the output will be a '1'. Otherwise the output will be a '0'.

Input Output

A B C
0 0 0
0 1 1
1 0 1
1 1 1

Okay. Thats the OR operator.
------------------------------------------------------------------------------------
The XOR operator
This operator is similar to the OR operator except for the case when both inputs are a '1'. The XOR operator has the condition that if either input A exclusively OR input Bexclusively is a '1', then the output will be a '1'. Otherwise the output will be a '0'.

So for the XOR case the output is a '1' if one and only one input is a '1'.

To put it in a table we get:

Input Output

A B C
0 0 0
0 1 1
1 0 1
1 1 0

So thats the XOR operator.


*There are a few other operators like NOT and AND that are also used in digital logic. The inputs are not necessarily limited to two in all cases, but the output for these is usually limited to 1 output.



Russ

$cirisme
September 9th 2003, 03:53 PM
Yes, thanks for the help.

I've been obsessed with learning higher-level math operators, especially with bitwise operators, so many thanks!

themuzicman
September 9th 2003, 03:54 PM
Don't make me come up with the logic to do a binary calculator in machine code. I don't think I'm up to it. Let's just say that it involved XOR and AND. :doh: My head hurts just thinking about it.

Michael

$cirisme
September 9th 2003, 03:55 PM
The more people that respond to this the dumber I feel :dunce:

themuzicman
September 9th 2003, 03:55 PM
Don't worry about it. We're just keepers of odd knowledge (KOOKs)

Em7add11
September 9th 2003, 03:56 PM
Cir, have you ever taken a structured programming course? Or did you learn it on your own?

$cirisme
September 9th 2003, 03:59 PM
I've learned everything I know on my own...which explains why I'm so bad :hrm:

But I have tons of expensive books! :bunny: :teeth:

Warcraft3
September 9th 2003, 04:01 PM
In fact even the "registers" that MM mentioned are made up of digital logic gates, which are made up of transisters.

And transisters are made up of P-N junctions in various arrangements. And P-N junctions are made up of 2 slabs of semiconducting material, which are made up of molecules, which are made up of atoms, which are made up of protons, electrons, and neutrons, etc...

Computers are fascinating because there are so many levels you can look at them from....eventually getting down to the quantum mechanics of what is happening inside of the P-N junctions.

Fun stuff.



Russ

Warcraft3
September 9th 2003, 04:04 PM
Today @ 03:55 PM post located here (http://www.theologyweb.com/forum/showthread.php?s=&postid=206943#post206943)
cirisme:

The more people that respond to this the dumber I feel :dunce:

Absolutely no reason for you to feel that way. Look at it this way......the stuff you learned you learned on your own while I spent like $30,000 in loans to have a professor teach it to me. And that doesnt count me buying the books. You should be proud of your independent learning.



Russ

themuzicman
September 9th 2003, 04:06 PM
Yeah, well, I didn't want to overwhelm cirisme with the physics of it all. :whack:

Michael

$cirisme
September 9th 2003, 04:09 PM
I know how the devil box works :whack: it's the math that fascinates me :teeth:

Warcraft3
September 9th 2003, 04:13 PM
Today @ 04:06 PM post located here (http://www.theologyweb.com/forum/showthread.php?s=&postid=206958#post206958)
themuzicman:

Yeah, well, I didn't want to overwhelm cirisme with the physics of it all. :whack:

Michael

:teeth: Sorry, I wasnt trying to go overboard or anything......but it all eventually comes down to some very weird equations in quantum and electromagnetics and even stranger physics.

I have always been fascinated with how they are so very abstract and totally practical all at the same time.

Truth really is stranger than fiction.



Russ

Warcraft3
September 9th 2003, 04:15 PM
Today @ 04:09 PM post located here (http://www.theologyweb.com/forum/showthread.php?s=&postid=206962#post206962)
cirisme:

I know how the devil box works :whack: it's the math that fascinates me :teeth:

LOL :lol: the devil box.

Funny description. And yes the math is very fascinating. I find the physics and engineering very fascinating also.

In fact I usually lump the math, physics, and engineering all together. They really are the same thing in my book.



Russ

themuzicman
September 9th 2003, 04:16 PM
Can you imagine trying to assemble the circuits into something that would compute even on a basic level, and then output something? Way too big for my brain.

Warcraft3
September 9th 2003, 04:25 PM
Today @ 04:16 PM post located here (http://www.theologyweb.com/forum/showthread.php?s=&postid=206967#post206967)
themuzicman:

Can you imagine trying to assemble the circuits into something that would compute even on a basic level, and then output something? Way too big for my brain.

Not all at once, no.

But try doing it section by section. Thats what we did in my class on VHDL. We built an 8-bit computer capable of adding two numbers piece by piece.

First we built things like AND, OR, and NOT gates.....then we built flip-flops.........then we worked our way up to building an adder........and registers..........and ROM, RAM, and a CPU.

It was all done slowly over the course of a semester. Now, it wasnt a modern 160 GIG computer or anything, but it was functionally a computer.

So from such a small scale I could try to imagine building a modern computer all by myself. It would probably take longer than a semester, in fact I would die of old age (and boredom) long before it was completed.......but its still possible.

Just a much larger scale, thats all. So in a way I could imagine it by projecting my VHDL project into a much larger scale.




Russ

AcousticJS
September 9th 2003, 05:50 PM
Much respect to steadele for building a computer. Have some pearls...

$cirisme
September 9th 2003, 05:53 PM
Yea, that is really cool! :thumb:

Jezz
September 11th 2003, 11:47 AM
Ran across this thread by accident because Russ won a pick-of-the-day with it, and I thought I could dust off some info that you guys would probably find interesting. :smile:


steadele:
But try doing it section by section. Thats what we did in my class on VHDL. We built an 8-bit computer capable of adding two numbers piece by piece.

First we built things like AND, OR, and NOT gates.....then we built flip-flops.........then we worked our way up to building an adder........and registers..........and ROM, RAM, and a CPU.
Hah! You used VHDL! That's cheating! Try drawing all the little transistors by yourself in 5 micron CMOS! That's designing a computer from scratch! :brow:

When I went to uni, we had a subject in final year where we designed a 4-bit ALU (Arithemetic/Logic Unit). This isn't a full-blown CPU, but it is an important part of every CPU. It contains the registers, the logic for adding/subtraction, and the logic for doing logic like shifts. It was my most favourite subject for the whole 4-year degree.

I've uploaded a picture of my completed design (I had to shrink it to 800 pixels wide so I've lost some detail :bawl:). A brief overview: the 4 bits are arranged top-to-bottom. There are 8 registers - these are to the left. The adder is in the middle (it does subtraction as well, using 2's complement). The logic unit is next to the adder. The shifter is the last thing in the chain - in the top-right of the circuit. There are two data buses - these run from left-to-right through the circuit, carrying the operands for the operation being performed. The control lines run top-to-bottom through the circuit.

For those who know the jargon (Russ might appreciate it), the registers are flip-flops. The adder is a simple ripple-carry adder. The logic circuits are a pseudo-NMOS multiplexers that can perform any bitwise logic operation between two operands. The shifter can do rotates, arithmetic shifts, and logical shifts - with or without carry.

Speaking of shifters, I thought I'd better answer cirisme's original question: yes, >> and << are shift operators. For example, the number 33, as an 8-bit binary number, looks like:

00100001

33 >> 1 means "33 with the bits shifted to the right one position":

00010000 (the last one "falls off" the end). Ie, 16.

33 << 1 means "33 with the bits shifted to the right one position":

01000010 (ie, 66).

Note that x >> n is equivalent to dividing x by 2^n, and x << n is equivalent to multiplying x by 2^n. This is the same principle as "jumping the decimal" when multiplying by powers of 10 in a decimal number system.

Shifts can get tricky when signed numbers come into play (and that's where the difference between >> and >>> becomes important in Java, for example), but it's getting late so I'll have to explain that another day. Hope that helps cirisme. :smile:

Warcraft3
September 11th 2003, 01:23 PM
Today @ 11:47 AM post located here (http://www.theologyweb.com/forum/showthread.php?s=&postid=209173#post209173)
Jezz:

Ran across this thread by accident because Russ won a pick-of-the-day with it, and I thought I could dust off some info that you guys would probably find interesting. :smile:


Hah! You used VHDL! That's cheating! Try drawing all the little transistors by yourself in 5 micron CMOS! That's designing a computer from scratch! :brow:
LOL I bet that would be fun too. For those who dont know what VHDL is........it is a program that can model the behaviour of digital components. So you design the stuff on there first (or some other program) and test it out. If it works and everything seems okay, you build it (there are more steps than this, but Im trying to be brief here). So I didnt actually build a PHYSICAL computer, but I designed and modeled one in VHDL. So before anyone objects and says "you really didnt design a computer then" keep in mind that this is the way it is done in industry also. It would kind of suck if you started manufacturing some new processor only to find out it doesnt work.....so its done on simulation software before entering the physical construction phase (with various steps in between).


When I went to uni, we had a subject in final year where we designed a 4-bit ALU (Arithemetic/Logic Unit). This isn't a full-blown CPU, but it is an important part of every CPU. It contains the registers, the logic for adding/subtraction, and the logic for doing logic like shifts. It was my most favourite subject for the whole 4-year degree.
Thats cool man!:cool: What program did you guys use? I never took the VLSI program at PSU, but one of my friends did....cool stuff.


I've uploaded a picture of my completed design (I had to shrink it to 800 pixels wide so I've lost some detail :bawl:). A brief overview: the 4 bits are arranged top-to-bottom. There are 8 registers - these are to the left. The adder is in the middle (it does subtraction as well, using 2's complement). The logic unit is next to the adder. The shifter is the last thing in the chain - in the top-right of the circuit. There are two data buses - these run from left-to-right through the circuit, carrying the operands for the operation being performed. The control lines run top-to-bottom through the circuit.
Nice picture Jezz. I can make out some of it....but its a bit blurry. What book did you use for that class? Im so torn between various topics in EE (Antennas, general EMag, digital design, Optics, Communications, Signal Processing, Solid State Physics, etc) that Im always looking for good books on topics I didnt have a class on.


For those who know the jargon (Russ might appreciate it), the registers are flip-flops. The adder is a simple ripple-carry adder. The logic circuits are a pseudo-NMOS multiplexers that can perform any bitwise logic operation between two operands. The shifter can do rotates, arithmetic shifts, and logical shifts - with or without carry.
:duh: When people talk like that, I just start drooling. I love, love, love this stuff!!!.



Russ (the other EE)

Jezz
September 11th 2003, 10:03 PM
steadele:
LOL I bet that would be fun too.
It certainly was... the most fun part about it was trying to make it as small as possible. See, there are certain rules as to how far apart certain features are allowed to be from each other - for example, polycrystalline silicon (the red stuff) is not allowed to be any closer than 2.5 microns to the metal-silicon connections (the rectangles with crosses in them). I spent countless hours just trying to shrink the thing so that it was as small as possible within those constraints. Even if I could make the whole thing only one square (2.5 microns) smaller, I would be happy! :smile: It's kinda like doing a jigsaw puzzle, but with more of a purpose. :smile:

For anyone who's interested (which is probably only Russ... :smile:) - the colours represent the following laerys of material (from bottom to top):

green - N-type silicon
orange/yellow - P-type silicon
red - polycrystalline silicon (aka polysilicon)
blue - metal 1 (ie, the first layer of metal)
purple/pink - metal 2 (ie, the second layer of metal)

grey crosses - connections between metal 1 and P-type silicon.
green crosses - connections between metal 1 and N-type silicon.

Wherever polysilicon crosses the N-type silicon, it forms an N-type transistor (MOSFET). The polysilicon is the "gate" of the transistor (for the laymen, the gate is the "on/off switch"). Similarly for P-type silicon.


For those who dont know what VHDL is........it is a program that can model the behaviour of digital components. So you design the stuff on there first (or some other program) and test it out. If it works and everything seems okay, you build it (there are more steps than this, but Im trying to be brief here). So I didnt actually build a PHYSICAL computer, but I designed and modeled one in VHDL. So before anyone objects and says &quot;you really didnt design a computer then&quot; keep in mind that this is the way it is done in industry also. It would kind of suck if you started manufacturing some new processor only to find out it doesnt work.....so its done on simulation software before entering the physical construction phase (with various steps in between).
Yep.

For the lay person, the difference between what I did and what Russ did is like the difference between assembly language and C or C++. So Russ designed more of a computer than what I did, but the small part that I designed I did at a lower level. (note: VHDL stands for Very High-level Description Language, if I recall correctly - is that right Russ?)


Thats cool man!:cool: What program did you guys use? I never took the VLSI program at PSU, but one of my friends did....cool stuff.
The program we used was called magic. It's a Unix-based program and is actually in the public domain, which is cool because it meant that I could install it on my Linux PC at home and do it there.


Nice picture Jezz. I can make out some of it....but its a bit blurry.
Yeah, sorry about that. I can send you the full-size image if you want, but it's still a little bit difficult to make out the details. You need to be able to zoom in more.


What book did you use for that class?
Pucknell and Eshragian (sp?) Basic VLSI Design. I can't say that I recommend it, though - it was written by a couple of the lecturers in the uni (hence, it was the recommended textbook...), but it wasn't all that useful. The most useful information we got was from the tutor - which, unfortunately, was not in book form... :smile:


Im so torn between various topics in EE (Antennas, general EMag, digital design, Optics, Communications, Signal Processing, Solid State Physics, etc) that Im always looking for good books on topics I didnt have a class on.
Heh, I know exactly how you feel! I had the same problem when I was at uni - I liked all the topics so much that I couldn't decide which electives to take. My solution to this problem was to take them all. :smile: In final year I took all of the electives bar one. Which was intellectually very satisfying, but it meant that I had a significant overload (not to mention 13 exams in a two-week period at the end of each semester... :eek:). Even that wasn't enough, though, coz I went back for more in subsequent years... :smile:


:duh: When people talk like that, I just start drooling. I love, love, love this stuff!!!.
Yep, that's right folks. We're a strange breed, us EEs. :smile:

HRG_new
September 12th 2003, 07:58 AM
09-09-2003 @ 09:25 PM post located here (http://www.theologyweb.com/forum/showthread.php?s=&postid=206969#post206969)
steadele:



Not all at once, no.

But try doing it section by section. Thats what we did in my class on VHDL. We built an 8-bit computer capable of adding two numbers piece by piece.

First we built things like AND, OR, and NOT gates.....then we built flip-flops.........then we worked our way up to building an adder........and registers..........and ROM, RAM, and a CPU.

It was all done slowly over the course of a semester. Now, it wasnt a modern 160 GIG computer or anything, but it was functionally a computer.

So from such a small scale I could try to imagine building a modern computer all by myself. It would probably take longer than a semester, in fact I would die of old age (and boredom) long before it was completed.......but its still possible.

Just a much larger scale, thats all. So in a way I could imagine it by projecting my VHDL project into a much larger scale.




Russ

Virtua