Mathematical Logic
Python
Binary Codes:
In order to understand this you must first understand binary.
lets work with base 2 first.
Base 2 works with a series of number 8 long(that is only 1's and 0's) so 10101010 is a base 2 binary number.
But what does that mean? It is very simple.in bast 2. It multiplies by 2 each time it goes up, so its something like this...
0 2 4 8 16 32 64 128.(this is base 2)
to better explain it a 1 is what represents the number and 0 represents nothing. So a 1 in the second spot would represent 2. Finally to get a number you add up all the numbers represented by 1's.
So 011 would be 6 because 2+4=6. lets look at a full example.
what would 00100111 be?
the answer is 228.
note, when using in the actual world, the string starts with 128 and goes down(128 64 32 16 8 4 2 0)
note 2, 0 is also represented as 1(the last number in the 8 bit string)
The first binary code is distance.
what is the distance between 11011011 and 10100110?
distance between two base 2 numbers is simply the number of different places in 1's and 0's
11011011
10100110
if we look at this, it is wherever a 1 is on one of the and a zero is on another.(the answer is 6)
Next is encoding with parity-check sums/decoding.
Nearest neighbor decoding
The easiest way to describe this is: the closest base 2 binary string to the one being presented
00000000
00001000
00110000
the first one would be the answer in the nearest neighbor method because it only has one different number
example from homework
C = ( 00000, 10011, 01010, 11001, 00101, 10110, 01111, 11100)
If the received word 11101 has exactly one error, can you determine the intended code word?
The answer is no, because according to the nearest neighbor you can have both 11100 and 11001 become 11101.
binary weight
binary weight is the minimum number of 1's that occur among code words
lets use T to represent any number
if T is even you use the algorithm (t-2)/2
if T is odd use the algorithm (t-1)/2
so if you receive 6 errors (6-2)/2=2
if its 5 (5-1)/2=2
network address'
lets say we have a IP address of 8.20.15.1 and a subnet mask of 255.000.000.000
what is the network address?
first you must convert everything to binary...(yea fun)
(subnet mask)
11111111.00000000.00000000.00000000
00001000.00101000.00001111.00000001
(ip adress)
after that we must add both binary codes together, but you must know the truth table first:
it goes like this
if both numbers don't match it equals ZERO
so....
011000
001011
=
001000
going back:
11111111.00000000.00000000.00000000
00001000.00101000.00001111.00000001
=
00001000.00000000.00000000.00000000
after that we convert it back into a "real" number and we have the network Id
...or we have 8.0.0.0
Python
Yesterday I started working on Pyhon. I decided to drop Perl for the moment because I couldn't find much use for it. When I looked at some major websites(facebook, twitter, yahoo, google, ect) don't seem to use Perl (or don't seem to need people at the moment) but all of them need a Python person.
I started with lists, and went into loops (the for and while) and used them to print out simple things
some example code is followed:
movies = ["the holy grail", 1975, "terry jones", 91,
["champman",
["palin", "cleese", "gilliam", "idle", "jones"]]]
We wanted to print all of this, however a "print(movies)" would not print everything out without all the [ " , ]
we ended up using the following code:
def print_lol(the_list):
for each_item in the_list:
if isinstance(each_item, list):
print_lol(each_item)
else:
print(each_item)
we defined the function and executed it to come out with each item separately
No comments:
Post a Comment