Mudah Belajar Sistem Digital dengan Programming Python

Bismillah,

Dibawah ini adalah Pengoperasian Operator Logika dengan Bahasa Python. Berikut daftar Operator Logika pada Python:
AND –> &
OR –> |
XOR –> ^
NOT –> not

Contoh Pengoperasian:
A AND B –> A & B
A OR B –> A | B
A XOR B –> A ^ B
NOT A –> not A

Dibawah ini contoh source kode python:
1. sd1.py:

#!c:/Python32/python.exe

# Copyright 2012 @ Muhammad Muntaza bin Hatta
# Lisensi: GPL v3                             
# Program dengan Operator LOGIKA
# web: muntaza.wordpress.com                  
# email: muntaza@binhatta.com                 

print ("A  \t| B  \t\t| A.B");
print ("=================================================================");

for i in range(2):
	if i == 0:
		A = False
	else:
		A = True
	for j in range(2):
		if j == 0:
			B = False
		else:
			B = True
		print (A, " \t|", B, "  \t| ", A & B);

1. sd2.py:

#!c:/Python32/python.exe

# Copyright 2012 @ Muhammad Muntaza bin Hatta
# Lisensi: GPL v3                             
# Program dengan Operator LOGIKA
# web: muntaza.wordpress.com                  
# email: muntaza@binhatta.com                 

print ("A  \t| B  \t\t| - A \t\t | - B");
print ("=================================================");

for i in range(2):
	if i == 0:
		A = False
	else:
		A = True
	for j in range(2):
		if j == 0:
			B = False
		else:
			B = True
		print (A, " \t|", B, " \t| ", not A, "  \t | ", not B);

3. sd3.py:

#!c:/Python32/python.exe

# Copyright 2012 @ Muhammad Muntaza bin Hatta
# Lisensi: GPL v3                             
# Program dengan Operator LOGIKA
# web: muntaza.wordpress.com                  
# email: muntaza@binhatta.com                 

print ("A  \t| B  \t\t| - A \t\t | - B \t\t| -A + -B");
print ("=================================================================");

for i in range(2):
	if i == 0:
		A = False
	else:
		A = True
	for j in range(2):
		if j == 0:
			B = False
		else:
			B = True
		print (A, " \t|", B, " \t| ", not A, "  \t | ", not B, "\t| ", (not A) | (not B));

4. sd4.py:

#!c:/Python32/python.exe

# Copyright 2012 @ Muhammad Muntaza bin Hatta
# Lisensi: GPL v3                             
# Program dengan Operator LOGIKA
# web: muntaza.wordpress.com                  
# email: muntaza@binhatta.com                 

print ("A  \t| B  \t\t| -(-A + -B)");
print ("=================================================================");

for i in range(2):
	if i == 0:
		A = False
	else:
		A = True
	for j in range(2):
		if j == 0:
			B = False
		else:
			B = True
		print (A, " \t|", B, "  \t| ", not ((not A) | (not B)));

screnshoot program setelah dijalankan:

5. sd5.py:


#!c:/Python32/python.exe

# Copyright 2012 @ Muhammad Muntaza bin Hatta
# Lisensi: GPL v3                             
# Program dengan Operator LOGIKA
# web: muntaza.wordpress.com                  
# email: muntaza@binhatta.com                 

print ("A  \t| B  \t\t| A XOR B");
print ("=================================================================");

for i in range(2):
	if i == 0:
		A = False
	else:
		A = True
	for j in range(2):
		if j == 0:
			B = False
		else:
			B = True
		print (A, " \t|", B, "  \t| ", A ^ B);

6. sd6.py:

#!c:/Python32/python.exe

# Copyright 2012 @ Muhammad Muntaza bin Hatta
# Lisensi: GPL v3                             
# Program dengan Operator LOGIKA
# web: muntaza.wordpress.com                  
# email: muntaza@binhatta.com                 

print ("A  \t| B  \t\t| C \t\t|\t (A XOR B) XOR C ");
print ("=================================================================");

for i in range(2):
	if i == 0:
		A = False
	else:
		A = True
	for j in range(2):
		if j == 0:
			B = False
		else:
			B = True
		for k in range(2):
			if k == 0:
				C = False
			else:
				C = True
			print (A, " \t|", B, "  \t| ", C, "   \t |"
			, (A ^ B) ^ C);

7. sd7.py:

#!c:/Python32/python.exe

# Copyright 2012 @ Muhammad Muntaza bin Hatta
# Lisensi: GPL v3                             
# Program dengan Operator LOGIKA
# web: muntaza.wordpress.com                  
# email: muntaza@binhatta.com                 

print ("A  \t| B  \t\t| C  \t\t|\t  D \t | (A & B) & (C & D) ");
print ("====================================================================");

for i in range(2):
	if i == 0:
		A = False
	else:
		A = True
	for j in range(2):
		if j == 0:
			B = False
		else:
			B = True
		for k in range(2):
			if k == 0:
				C = False
			else:
				C = True
			for l in range(2):
				if l == 0:
					D = False
				else:
					D = True
				print (A, " \t|", B, "  \t| ", C, "   \t |"
				, D, "   \t| ", (A & B) & (C & D));

Screenshoot dari program diatas:

Dari Contoh-contoh diatas, terlihat betapa mudahnya pengoperasian LOGIKA dengan Python. Namun harus diperhatikan urutan Operasinya dengan menggunakan tanda kurung, Misalnya:

(A AND B) OR (C XOR (NOT D))

Urutan Operasinya adalah:
1. A di AND kan dengan B (A AND B)
2. D di NOT kan (NOT D)
3. (NOT D) di XOR kan dengan C
4. (A AND B) di OR kan dengan (C XOR (NOT D))

Bila diterjemahkan kedalam Python menjadi:
(A & B) | (C ^ (not D))

Semoga Tulisan ini bermanfaat

Walhamdulillah. Semoga Allah Rabbuna Jalla Wa ‘Ala Memudahkan saya untuk tinggal di Banjarbaru

ditulis oleh: Al faqir ilaa maghfirati rabbihi Abu Husnul Khatimah Muhammad Muntaza bin Hatta

About these ads

2 thoughts on “Mudah Belajar Sistem Digital dengan Programming Python

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s