CSC104H1 Lecture 19: Binary Number

45 views2 pages

Document Summary

> #b000 #b001 #b010 #b011 #b100 #b101 #b110 #b111. > #b1000 #b1001 #b1010 #b1011 #b1100 #b1101 #b1110 #b1111. > ; adding 1 on the reversed fourth position to add 8. ; add 0 at th elast position to multiply by 2. > ; now we want to come up with an approach for converting from secimal to binary. > (define (numbers->bits n) (cond [(zero? n) (list)] [(even? n) (append (number->bits (/ n 2)) (list 0))] [else (sppend (numbers->bits (/ (- n 1) 2)) (list 1))])) ; - harder to write up in racket. ; 32 doesn"t fit, put a 0 there. ; 1 - 1 = 0 -> done. ; 0 is < all of remaining powers of 2 (1, 2, 4), so we have 0s. Try to figure out the power of 2 for each column with a 1. then add those ip to get the decimal number.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents