a. 1/3
b. 1/10
3.15.1 Write down the bit pattern in the mantissa assuming a
floating point format that uses binary numbers in the mantissa (essentially what
you have been doing in this chapter). Assume there are 24 bits, and you do not need
to normalize. Is this representation exact?
a) ⅓ can’t be represented since it repeats 3333 infinitely, and we are in base 2 therefore we must round up a little
010101010101010101010110
b) 1/10 also can’t be represented in base 2 and must be approximated.
000110011001100110011001
Work on Spreadsheet.
https://docs.google.com/spreadsheet/ccc?key=0Anpg-UsmVkpFdFY2cm1OeVRZZUQtS0g1Nk1kNjltUGc&usp=sharing
3.15.2 Write down the bit pattern in the mantissa assuming a
floating point format that uses Binary Coded Decimal (base 10) numbers in the
mantissa instead of base 2. Assume there are 24 bits, and you do not need to nor-
maize. Is this representation exact?
a)This also can’t be represented exactly
0011 = 3
.3 3 3 3 3 3
001100110011001100110011
b)This is our first number that CAN be represented exactly.
1/10 = .1
0001 = 1
.1 0 0 0 0 0
000100000000000000000000
3.15.3 Write down the bit pattern assuming that we are using
base 15 numbers in the mantissa instead of base 2. (Base 16 numbers use the sym-
bos 0–9 and A–F. Base 15 numbers would use 0–9 and A–E.) Assume there are 24
bits, and you do not need to normalize. Is this representation exact?
a)The first case in which ⅓ can in fact be represented exactly.
1/3 = 5/15
5 = 0101
5 0 0 0 0 0
010100000000000000000000
b)Can’t Be Represented Exactly
(1/10) = (x/15)
x = 1.5
Round(1.5) = 2
2 = 0010
0010 0010 0010 0010 0010 0010
3.15.4 Write down the bit pattern assuming that we are using
base 30 numbers in the mantissa instead of base 2. (Base 16 numbers use the sym-
bos 0–9 and A–F. Base 30 numbers would use 0–9 and A–T.) Assume there are 20
bits, and you do not need to normalize. Is this representation exact? Do you see any
advantage to using this approach?
a)⅓ = 10/30
10 = 01010
01010 00000 00000 00000
b) 1/10 = 3/30
3 = 00011
00011 00000 00000 00000
Using a larger base allows a greater flexibility when non normalized at the cost of precision. Base 30 as represented above has 4 decimal digits, as opposed to base 10 above, which has 6.
This is mentioned here in a comparison with storing the value of the speed of light. “floating-point numbers cannot represent point coordinates with atomic accuracy at galactic distances, only close to the origin” the smaller the number, the greater the precision we need. The larger the number, the greater a exponent value we need.
I also created a Mips program to do parts of these calculations.
.data
Ask_base: .asciiz "\Please Enter a Base\n"
Ask_top: .asciiz "\Please Fraction Top\n"
Ask_bottem: .asciiz "\Please Fraction Bottem\n"
sig: .asciiz "\Significand\n"
space: .asciiz "\n"
not_possible: .asciiz "\This Fraction Cannot be accurately represented\n"
.text
main:
la $a0, Ask_base
li $v0, 4
syscall #print Ask_base
li $v0, 5
syscall
move $t0, $v0 #t0 is our base
la $a0, Ask_top
li $v0, 4
syscall #print Ask_top
li $v0, 5
syscall
move $t1, $v0 #t1 is top of fraction
la $a0, Ask_bottem
li $v0, 4
syscall #print Ask_bottem
li $v0, 5
syscall
move $t2, $v0 #t1 is bottem of fraction
#goal is to test first if its possible to represent
#if something can't be represented, it requires a fair amount of estimation
#this is outside the scope of this program
mulu $s0, $t0, $t1
divu $s0, $t2
mfhi $s1
mflo $s2
beqz $s1, calc #if there is a remainer, we print and exit, else we continue
la $a0, not_possible
li $v0, 4
syscall #print not_possible
j done
calc: #not that there is much calc
la $a0, sig
li $v0, 4
syscall #significand
li $v0, 1 #print_int
move $a0, $s2
syscall
la $a0, space
li $v0, 4
syscall #print space
#************** Convert to Bit notation *************************#
move $t2, $s0 # Move to temp
li $s1, 24 # Set up a loop counter - assuming 24 bit
Loop:
ror $t2, $t2, 1 # Roll the bits left by one bit - wraps highest bit to lowest bit (where we need it!)
and $t0, $t2, 1 # Mask off lowest bit
add $t0, $t0, 48 # Combine it with ASCII code for '0', becomes 0 or 1
move $a0, $t0 # Output the ASCII character
li $v0, 11
syscall
subi $s1, $s1, 1 # Decrement loop counter
bne $s1, $zero, Loop # Keep looping if loop counter is not zero
#I started to do this but I stopped here, it doesn't take into account the appropriate bit size. and the calculations themselves are slightly off
#example, a base 16 needs 4 bits, int 5 isn’t 1110 in binary
#I kept this in here as reference to the attempt
done:
#example
#input base 15
#input top 1
#input bottem 3
##output##
#Significand
#5
#111000000000000000000000
|
Looking great work dear. I'm happy to read your blog, really appreciated this quality work. Thanks for sharing. If you want to know about Belkin Router setup you can visit here.
ReplyDelete