Wednesday, September 22, 2010

write regular expressions for the following:

1) a sibilant followed by any letter followed by asterisk symbol
2) a capital letter except G followed by anything

1) [sczSCZ][A-Za-z][\*]
2) [A-FH-Z]*

* convert from binary to decimal
* convert from decimal to binary
* add two binary numbers
* subtract two binary numbers

HW: Convert the following numbers to binary and add them:
27 + 56
1 + 6
7 + 3
give me the binary result

HW: Convert the following numbers to binary and subtract them:
8 - 5
12 - 9
20 - 10

remember also the cool trick with 10's complement. and show your friend.

how do we store negative numbers?
-83
three different approaches

* sign bit

83 in binary is  0101 0011
-83 in binary is 1101 0011

* use the one's complement
83 in binary is  0101 0011
-83 in binary is 1010 1100

* use the two's complement
83 in binary is  0101 0011
-83 in binary is 1010 1101

Two's complement is "best"
in terms of values you can store

8 bits lets me store 256 distinct values
2 ^ number of bits
0000 0000 = 0
0000 0001 = 1
0000 0010 = 2

0 .. 255

-0
0000 0000

sign bit
1000 0000

one's complement
1111 1111

two's complement
0000 0000

1 comment:

  1. Can anyone please tell me where we have to submit the 'convert to binary then add/subtract' homework?

    ReplyDelete