Übungsblatt 6 Name: Joe User Tutor: ???? ========== AUFGABE 6.1 (Zahlensysteme) ========== 6.1.1 a = 4*7^0 + 3*7^1 + 2*7^2 + 1*7^3 = 4 + 21 + 98 + 343 = 466 b = 3412 c = 5FE d = 81 e = A5 f = 201 g = 245 h = 11001101 i = 10111 ========== 6.1.2 Welchen Vorteil hat das Hexadezimalsystem gegenüber dem Dezimalsystem im Computerumfeld? Welchen Vorteil bietet es gegenüber dem Oktalsystem? Es ist wesentlich einfacher, mit Hilfe einer Tabelle Zahlen zwischen dem Hexadezimalsystem und dem vom Computer verwendete Binärsystem hin- und herzurechnen, da eine Stelle im Hexadezimalsystem genau vier Stellen im Binärsystem entspricht. Eine Stelle im Hexadezimalsystem entspricht 4 binären Stellen, im Oktalsystem 3 binären Stellen. Der Computer rechnet normalerweise in Bytes (8 bit), so daß ein Byte genau zwei Hexadezimalstellen entspricht. ========== AUFGABE 6.2 (Python: Dictionaries, Strings und Module) ========== 6.2.1, 6.2.2 und 6.2.3 Skript: import sys, optparse # zaehlen der Woerter occ = {} contents = sys.stdin.read() line = contents.split() for s in line: if s in occ: occ[s] += 1 else: occ[s] = 1 # Mindestanzahl als Parameter parser=optparse.OptionParser() parser.add_option("-m", "--min", dest="min", type=int, default=100) (options, args) = parser.parse_args() # sortieren der Ausgabe sorted_occ = sorted(occ, key=lambda k: occ[k]) # Ausgabe for key in sorted_occ: val = occ[key] if val > options.min: print "%5d %s" % (occ[key], key) ========== 6.2.4 Befehl und Ausgabe: > ls -R /usr/share | python occ.py --min=300 occ.py 316 README.Debian 665 changelog.gz 1148 changelog.Debian.gz 1247 copyright 2369 README