E2011: Theoretical fundamentals of computer science Topic 3: Numeral systems - Exercises Vlad Popovici, Ph.D. Fac. of Science - RECETOX Problem 1 Implement a 2-bit adder using logical gates. Vlad Popovici, Ph.D. (Fac. of Science - RECETOX)E2011: Theoretical fundamentals of computer science Topic 3: Numeral systems - Exercise2 / 8 Plan which numbers can be represented on 2 bits? Vlad Popovici, Ph.D. (Fac. of Science - RECETOX)E2011: Theoretical fundamentals of computer science Topic 3: Numeral systems - Exercise3 / 8 Plan which numbers can be represented on 2 bits? what is the range of results? Vlad Popovici, Ph.D. (Fac. of Science - RECETOX)E2011: Theoretical fundamentals of computer science Topic 3: Numeral systems - Exercise3 / 8 Plan which numbers can be represented on 2 bits? what is the range of results? how many bits you need for the result? Vlad Popovici, Ph.D. (Fac. of Science - RECETOX)E2011: Theoretical fundamentals of computer science Topic 3: Numeral systems - Exercise3 / 8 Plan which numbers can be represented on 2 bits? what is the range of results? how many bits you need for the result? write the truth table and derive the fuctions for the outputs Vlad Popovici, Ph.D. (Fac. of Science - RECETOX)E2011: Theoretical fundamentals of computer science Topic 3: Numeral systems - Exercise3 / 8 Plan which numbers can be represented on 2 bits? what is the range of results? how many bits you need for the result? write the truth table and derive the fuctions for the outputs design the circuit Vlad Popovici, Ph.D. (Fac. of Science - RECETOX)E2011: Theoretical fundamentals of computer science Topic 3: Numeral systems - Exercise3 / 8 Solution Input: a = [a1a0], b = [b1b0]. Output: s = [cs1s0]; c: carry Truth table: a1 a0 b1 b0 c s1 s0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 1 0 0 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 0 0 1 1 0 1 1 1 1 0 1 1 1 1 Vlad Popovici, Ph.D. (Fac. of Science - RECETOX)E2011: Theoretical fundamentals of computer science Topic 3: Numeral systems - Exercise4 / 8 Solution Input: a = [a1a0], b = [b1b0]. Output: s = [cs1s0]; c: carry Truth table: a1 a0 b1 b0 c s1 s0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0 1 1 0 1 1 0 1 0 0 0 0 1 0 1 0 1 0 1 0 0 1 1 0 0 1 1 0 1 1 1 1 0 0 1 0 0 0 0 1 0 1 0 0 1 0 1 1 1 0 1 0 1 0 0 1 0 1 1 1 0 1 1 1 0 0 0 1 1 1 1 0 1 1 0 0 1 1 1 0 1 0 1 1 1 1 1 1 1 0 Vlad Popovici, Ph.D. (Fac. of Science - RECETOX)E2011: Theoretical fundamentals of computer science Topic 3: Numeral systems - Exercise5 / 8 Vlad Popovici, Ph.D. (Fac. of Science - RECETOX)E2011: Theoretical fundamentals of computer science Topic 3: Numeral systems - Exercise6 / 8 Problem 2 Using bitwise operations, extract the R, G, B values from a HTML-like specification (in hexa) of the form ”#RRGGBB”, where each symbol corresponds to a hexa digit. Example, from ”#ABCDEF”, you should get R=”AB”, G=”CD”, B=”EF”. Vlad Popovici, Ph.D. (Fac. of Science - RECETOX)E2011: Theoretical fundamentals of computer science Topic 3: Numeral systems - Exercise7 / 8 Solution RGB R ed (R )rrrr rrrr 23 16 G reen (G ) gggg gggg 15 8 B lue (B ) bbbb bbbb 7 0 let x be the input value (on 24 bits, i.e. 6 bytes) R = x >> 16 (right shift by 16 bits) G = (x << 4) >> 16 (left shift followed by right shift) B = x&FF (bitwise AND) can you see what happened in each case? can you find other solutions? Vlad Popovici, Ph.D. (Fac. of Science - RECETOX)E2011: Theoretical fundamentals of computer science Topic 3: Numeral systems - Exercise8 / 8