YouTube2Text

[CS61C FA20] Lecture 02.2 - Number Representation: Conversions — Transcript

by CS 61C Departmental · 4,028 words · 630 segments · language en · Watch on YouTube

Full transcript

  1. 0:00and welcome back now let's see
  2. 0:03how to work with binary decimal and
  3. 0:06hexadecimal numbers and how to convert
  4. 0:08among that triangle binary decimal to
  5. 0:10hexadecimal
  6. 0:11so let's begin at the beginning we're in
  7. 0:13first grade we're learning about base 10
  8. 0:15numbers
  9. 0:16and you're thinking to yourself uh i
  10. 0:18paid money for this let's go
  11. 0:20no it makes it makes it's important to
  12. 0:22start from the beginning to see the
  13. 0:23analogies of how you were thinking about
  14. 0:25numbers in the first place
  15. 0:26so if you remember the teacher taught
  16. 0:28you that you had ten different
  17. 0:29characters
  18. 0:30zero through nine we're in base ten by
  19. 0:32the way the question of why are we in
  20. 0:34base ten
  21. 0:35ten fingers uh if we were
  22. 0:38in simpson's land we'd be in base eight
  23. 0:41because they have four fingers
  24. 0:42see simpsons thing so if i give you the
  25. 0:45number 3271
  26. 0:48by the way from now on starting now
  27. 0:51in general if i don't write any base
  28. 0:52it's the default is going to be base 10
  29. 0:55okay uh in fact i i i'm even going to
  30. 0:58write the letter out of t e n
  31. 1:00there because base 1 0 is ambiguous but
  32. 1:02we'll talk about that in a couple slides
  33. 1:05so 3271 that means is the same as 3271
  34. 1:09subscript 10. okay i can even grab a pen
  35. 1:12here
  36. 1:13and just annotate that so i'm going to
  37. 1:14write a subscript here to indicate
  38. 1:17that we're in base 10. what that really
  39. 1:19meant is
  40. 1:21three thousands plus two hundreds
  41. 1:25plus seven tens plus one
  42. 1:28one okay and we add them all up this is
  43. 1:30like a coefficient times
  44. 1:32times this term so it's three thousands
  45. 1:34two hundreds
  46. 1:35seven tens and one that gives you 3271
  47. 1:38there by the way i could have said
  48. 1:40look i've got three i got a lot of dash
  49. 1:42marks
  50. 1:43i've got a lot of when you're in prison
  51. 1:45not that i would know about
  52. 1:46being in prison but if you're in prison
  53. 1:48you might have lots of dashboards how
  54. 1:49many days you've been there every day
  55. 1:50you
  56. 1:51scratch something into the wall well i
  57. 1:52might have that number of dash marks
  58. 1:54just and that's actually base one you've
  59. 1:56just got dash marks it's called
  60. 1:58uh tally counting i think so if i want
  61. 2:00to convert that to base ten i'd have to
  62. 2:02count them up and then figure out how
  63. 2:03many
  64. 2:03ten how many thousands and how many tens
  65. 2:05it's actually an interesting process of
  66. 2:07counting from tally
  67. 2:08marks to base 10.
  68. 2:11base 2 is exactly the same thing as base
  69. 2:1310 just subtle
  70. 2:15where i said you had 10 characters
  71. 2:16represented 10 digits
  72. 2:18now i have 2 0 and 1.
  73. 2:22and in fact we're always going to start
  74. 2:23from 0 and count the way up when we get
  75. 2:25past 10 we'll see how to do this in
  76. 2:26hexadecimal by actually leaking into the
  77. 2:27letters
  78. 2:29so if i have 1 1 0 1 now i now need to
  79. 2:32indicate that 1 1 0 1 is not in base 10.
  80. 2:35it's in base 2.
  81. 2:36so i would either write 0 b in front of
  82. 2:38it okay if i see 0 b
  83. 2:40that means i'm in a binary number or i
  84. 2:42can write it base
  85. 2:442 subscript 2 or i can say 1 1 0 1
  86. 2:47in binary okay and i'm saying translate
  87. 2:491101 and bind it
  88. 2:511 101 from base 10 to binary that's what
  89. 2:53i'm really asking you to do
  90. 2:55well how do we do this the same way what
  91. 2:58we do
  92. 2:59is if you recall before i'm going to go
  93. 3:01back to this slide this 10 to the 3 this
  94. 3:03is the base
  95. 3:04to some power look at that 10 to the 0
  96. 3:0710 to the 1
  97. 3:0810 to the 2 10 to the 3. the same thing
  98. 3:10here let's take the base
  99. 3:12to the different powers and this in a
  100. 3:14way gives
  101. 3:15like a column heading you can sometimes
  102. 3:17i even do this sometimes i say
  103. 3:19draw it like this and i say 1
  104. 3:222 what's 2 squared 4.
  105. 3:26what's 2 to the 3 8 and then i say well
  106. 3:30what's the value in that and so i kind
  107. 3:32of say i write my number one
  108. 3:34one zero one and basically that's
  109. 3:37it's the the column heading times the
  110. 3:39value below it so you see this here it's
  111. 3:41one
  112. 3:41eight one four no twos and one one
  113. 3:46it's almost like have an analogy we're
  114. 3:47going to see in a second if i got boxes
  115. 3:49from amazon
  116. 3:50and the boxers labeled one egg in this
  117. 3:52one
  118. 3:53here's an empty box i guess it's an
  119. 3:54empty box this is the two box
  120. 3:56this is full of eggs it's four and this
  121. 3:58is full of eggs it's eight
  122. 4:00how many total eggs do i have so i think
  123. 4:01about that sometimes the boxes come
  124. 4:02empty or full but they're either only
  125. 4:04empty or full in here
  126. 4:05in this particular case so eight and
  127. 4:07four and one is thirteen therefore one
  128. 4:08one zero one
  129. 4:09is 13. pretty cool
  130. 4:13base 16. you got to be warmed up let's
  131. 4:16go let's rock and roll
  132. 4:17this is called hexadecimal so now you're
  133. 4:19going to say well dan i have
  134. 4:2016 digits but i can only i can probably
  135. 4:24use the first 10 from decimal that's
  136. 4:25right so what do i do
  137. 4:27you're going to leak into the letters so
  138. 4:30we're going to go a through f
  139. 4:31so all of a sudden a is now a number b
  140. 4:34is a number
  141. 4:35and the way that works is a is 10. just
  142. 4:37keep locked at it
  143. 4:38b is 11. c is 12 d is 13 e is 14
  144. 4:41f is 15. so i would like you to memorize
  145. 4:44that actually i really would like you to
  146. 4:46memorize that i'd like to be proud to
  147. 4:47say all of my 621c graduates
  148. 4:49know that and know how to connect that
  149. 4:50so i'm going to ask you here we go a5 i
  150. 4:52made a5
  151. 4:53in hexadecimal written in hexadecimal
  152. 4:57dollars today how much money did i make
  153. 4:59that's pretty cool now
  154. 5:00you could also have a number 1101 is a
  155. 5:03valid hexadecimal number so again we
  156. 5:04still have to indicate what our base is
  157. 5:06when i'm giving you a number
  158. 5:07so i can either say a5 a hexadecimal
  159. 5:10number a5 what's that in decimal that's
  160. 5:12what i'm asking doing here
  161. 5:13or i can precede it with 0x just like 0b
  162. 5:170x that tells you unambiguously that
  163. 5:21that's a hexadecimal number
  164. 5:23or again you can write a subscript 16.
  165. 5:26we do our same thing we write our
  166. 5:27columns here's our columns
  167. 5:29the first column is always one the
  168. 5:31second column is always b this is this
  169. 5:33is by the way
  170. 5:33this is always base to the zero base to
  171. 5:36the one so
  172. 5:37base to the one is 16 base to the 2 is
  173. 5:39256
  174. 5:41etc so what have i got well
  175. 5:44a5 i write a5 what are right over here
  176. 5:48zero there are always leading zeros we
  177. 5:51just ignore them right there's all
  178. 5:52if i said i made 12 dollars in in
  179. 5:54decimal 12 today
  180. 5:55i also made 0 12. i also made 0 0 12. we
  181. 5:57just don't say the zeros
  182. 5:59okay so a5 let's do it so a times 16.
  183. 6:03wait what well i have to look up so a is
  184. 6:0510
  185. 6:0610 times 16 is 160 plus 1 times
  186. 6:095 times 1 is 5. 160 plus 5 is 165. so if
  187. 6:13i made a5
  188. 6:14a hexadecimal hex a5 dollars i made 165
  189. 6:18in decimal dollars pretty cool right
  190. 6:22every base is base 10. here's an alien
  191. 6:26and here's an astronaut bail
  192. 6:27alien says there are 10 rocks astronaut
  193. 6:30says
  194. 6:31oh yeah you must be using base four uh
  195. 6:34uh see i use base ten and alien says no
  196. 6:37no i use base ten what's base four
  197. 6:40because in every base there's a ten
  198. 6:43and in fact every base ten is their base
  199. 6:48base two remember binary one zero is two
  200. 6:51base decimal one zero is ten hexadecimal
  201. 6:54one
  202. 6:54zero is sixteen so every base has a ten
  203. 6:58and every base is that base all your
  204. 7:01base
  205. 7:02are belong to us so now let's convert
  206. 7:04we've now converted from
  207. 7:06decimal converted from binary and hex to
  208. 7:09decimal
  209. 7:10let's now convert from decimal to binary
  210. 7:13and to hex
  211. 7:15so let's let's reverse it don't tell
  212. 7:17them this is the same number we
  213. 7:18converted before okay
  214. 7:1913. so this is an hour this is actually
  215. 7:22the first algorithm that's i mean that
  216. 7:23was an algorithm too but it was a little
  217. 7:24easy
  218. 7:24this is an algorithm that has some ifs
  219. 7:26then we have to make a decision here
  220. 7:28the way i think of this my analogy for
  221. 7:30this this has worked well for
  222. 7:31students when i've taught them to think
  223. 7:34of the following
  224. 7:34i've got these boxes to ship back to
  225. 7:36amazon all labeled
  226. 7:38in those bases i've got a box labeled
  227. 7:40one box labeled two a box labeled four
  228. 7:42box labeled eight okay
  229. 7:45i want to reduce my postage amazon will
  230. 7:48only take
  231. 7:49a full box back remember it's either
  232. 7:50full or empty i won't take a full box
  233. 7:52back
  234. 7:53so i first start by this i say i got 13
  235. 7:57and the first the algorithm says this is
  236. 7:59the column number by the way you know to
  237. 8:01the left of this is a 16
  238. 8:03this i should write this better there's
  239. 8:04a 16 there's a 32
  240. 8:07etc on the left of that so i can start
  241. 8:09there let's start with the 16. this just
  242. 8:10just to be just to go rogue for a second
  243. 8:13i say
  244. 8:14is the column number less than or equal
  245. 8:16the number i have left the number of
  246. 8:18eggs i have left to you know
  247. 8:19boy those chickens were productive so i
  248. 8:22got to ship 13
  249. 8:23eggs back to amazon i got a box said 16
  250. 8:25and i know amazon will
  251. 8:26take a full box so can i fit 13 in a
  252. 8:30box of 16 and fill it up i can't so i
  253. 8:33write a zero here
  254. 8:34boop pretty cool go to the next guy
  255. 8:37so let's try this then i go to the eight
  256. 8:39and i've actually animated this for you
  257. 8:41so i say can i fit and fill an
  258. 8:44eight box with whatever eggs i've got
  259. 8:46left which is thirteen i say yes
  260. 8:49then i ask how many of those
  261. 8:52boxes can i fill well here only one in
  262. 8:55fact in binary it's only gonna
  263. 8:56be one or zero but so we'll see in hex
  264. 8:57it's actually more we'll have to say in
  265. 8:59general be more than just one
  266. 9:01so once i filled eight how many do i
  267. 9:03have left cross it off i say i've got
  268. 9:05five left
  269. 9:06let's keep going i go to my next box can
  270. 9:09i fill a four
  271. 9:10yes i can how many times can i fill the
  272. 9:13four only once
  273. 9:14so therefore i fill it up i take i fill
  274. 9:17the four how many is left after i fill
  275. 9:18the four box
  276. 9:19one left i've got the next box we've got
  277. 9:22a two can i fill the two with only one
  278. 9:24egg
  279. 9:24i cannot then i can't use it so a zero
  280. 9:27in that one
  281. 9:28go to the next one can i fill a box of
  282. 9:30one that box labeled one with one
  283. 9:32egg yes i can how many times can i fill
  284. 9:34it only once there's one and i've seen
  285. 9:36now
  286. 9:37and i just by the way i stopped when my
  287. 9:38my sum is zero so once i cross it off
  288. 9:40and i get my zero i stop and i just put
  289. 9:42zeros in the rest of these guys if i
  290. 9:43have if i happen to let's say i had
  291. 9:44eight i'd put a one for eight and put
  292. 9:46all the zeros i could just
  293. 9:47you know short circuit it and go up
  294. 9:48right right to the end
  295. 9:50so converting 13 to binary
  296. 9:531101 is the equivalent by going down
  297. 9:56thinking of the amazon egg boxes you got
  298. 9:59it
  299. 9:59now let's do this in hexadecimal
  300. 10:04165 again don't tell the students but
  301. 10:06this is the same number we had before
  302. 10:08let's go 165 which is a
  303. 10:11decimal number i want to convert that to
  304. 10:14hexadecimal
  305. 10:15so start with my columns in fact i've
  306. 10:17added some extra ones here now
  307. 10:194096. so i asked the question
  308. 10:22can i fill the 4096 box probably 16 to
  309. 10:24the three is 4096
  310. 10:25another nice thing to memorize but i
  311. 10:27wouldn't worry about that one too much
  312. 10:30i cannot zero let's go to the next guy
  313. 10:33can i fill the 256
  314. 10:35labeled box with 165 i cannot zero
  315. 10:39can i fill a 16 box yes i can
  316. 10:43how many see this is the first time it's
  317. 10:45come up how many
  318. 10:4716s how many 16 boxes can i fill with my
  319. 10:50165 eggs sitting all
  320. 10:52on my floor 10 of them do i write
  321. 10:5510 no i look up in that base
  322. 10:58what the character the digit that
  323. 11:01represents that is
  324. 11:02and it's going to be an a i would list
  325. 11:03an a not a 10 i'd list an
  326. 11:05a so far once i have a or
  327. 11:0810 of these 16 boxes that's 160
  328. 11:13how many is left five and i keep going
  329. 11:16same algorithm
  330. 11:17this is the same algorithm for every
  331. 11:18base isn't that pretty cool so now you
  332. 11:20know
  333. 11:20i could actually ask you an exam to
  334. 11:22convert to some base you haven't heard
  335. 11:23of before
  336. 11:24and you should be able to do that same
  337. 11:25algorithm okay so
  338. 11:27five left i've got boxes with one how
  339. 11:29many can i fill
  340. 11:31uh you can can i fill a box with one yes
  341. 11:32i can how many of those boxes can i fill
  342. 11:34five i fill the five i'm down to zero
  343. 11:37and i'm done
  344. 11:38it's pretty cool this is fun right so
  345. 11:41now
  346. 11:42of the triangle here's a decimal binary
  347. 11:45hex
  348. 11:46i can now go back and forth that's
  349. 11:47pretty cool i can't go this way yet
  350. 11:49until this slide
  351. 11:51boom binder to hex so i've got some
  352. 11:54binary number
  353. 11:55how do i convert it to to hex here's the
  354. 11:57key don't make this mistake
  355. 12:00you have to left pad it which means add
  356. 12:03zeros to maybe you always add zeros to
  357. 12:05the left
  358. 12:05you have to left pad it so that it's all
  359. 12:07the length of that binary digit
  360. 12:10always is a multiple of four if you do
  361. 12:13this
  362. 12:13it'll work out trivially so if i give
  363. 12:15you one one one one
  364. 12:17four ones and a zero convert it to hex
  365. 12:21what have i got one one one one
  366. 12:24one one one one zero to hex well it's
  367. 12:27only five
  368. 12:28it's five let's add three more now i've
  369. 12:30got
  370. 12:32eight characters three zeros four ones
  371. 12:35and a zero you see it right here okay
  372. 12:37now this guy is eight
  373. 12:41binary digits or bits by the way i
  374. 12:43didn't mention binary digits
  375. 12:45bi and the ts from digits becomes bits
  376. 12:50that's why we call them bits so look
  377. 12:52that up now i have this
  378. 12:53look that up here's the table this table
  379. 12:56right here boom
  380. 12:58boom memorize this table
  381. 13:01it will save you in time and will make
  382. 13:03you feel like
  383. 13:04oh stand a little taller 61c i know i
  384. 13:07now know i'm fluent with hexadecimal
  385. 13:09you can ask me boom what's uh i don't
  386. 13:12know
  387. 13:12let's look at it by the way the way you
  388. 13:14do this then you look it up by
  389. 13:15fours one of the things you're going to
  390. 13:17notice is
  391. 13:19four binary digits remember this from
  392. 13:21before the first video
  393. 13:22is two to the four sixteen things
  394. 13:26well sixteen things is this number of
  395. 13:28hexadecimal
  396. 13:30options zero through f one accidental
  397. 13:32digit is
  398. 13:3316 things so there's my four there's my
  399. 13:3616 binary bits i just looked them up i
  400. 13:39say
  401. 13:40what's that i just look it up boom
  402. 13:43e so i write e
  403. 13:46what's 0 i look it up 1
  404. 13:50answer is 1e easy you could also
  405. 13:53not do the padding but start from the
  406. 13:54right okay if you start from the right
  407. 13:56it doesn't matter so i
  408. 13:57go here there's that 1 1 1 0. that's my
  409. 14:00e
  410. 14:01this is my one with some leading zeros
  411. 14:03okay here's here's an important thing
  412. 14:05if you go from the left you will get it
  413. 14:07wrong
  414. 14:09one one one one that would be f
  415. 14:12zero and i can't pad to the right
  416. 14:14because that changes the number
  417. 14:16so it is not f zero it is not f zero
  418. 14:19very important that you see that okay so
  419. 14:21start from the right or
  420. 14:22pad it so that's always multiple to four
  421. 14:24and just that doesn't matter which way
  422. 14:25you go
  423. 14:27hex to binary piece of cake let's look
  424. 14:29them up
  425. 14:30literally look them up concatenate it
  426. 14:32all together and then drop the leading
  427. 14:33zeros
  428. 14:34so one e so what's your e
  429. 14:37there's your e we did this already
  430. 14:40what's your one
  431. 14:41drop leading zeros cross those off what
  432. 14:43do you get
  433. 14:44one one one one zero okay binary hex
  434. 14:47that's the triangle
  435. 14:48huh with the thing they made the
  436. 14:50triangle okay
  437. 14:53so four bits
  438. 14:57okay let's start for the eight i start
  439. 14:58with the second bullet point here eight
  440. 14:59bits is called a byte
  441. 15:00just historically it's called a byte
  442. 15:03okay
  443. 15:04now four bits half of that as you see
  444. 15:06here this is this is my
  445. 15:08four bit column that's called a nibble
  446. 15:11get it a bite
  447. 15:12see a bite and then a a nibble
  448. 15:16you also you also have i've i've tried
  449. 15:19to advocate that two bits should be like
  450. 15:20a
  451. 15:21taste you know i don't know nobody's
  452. 15:23ever bought under there
  453. 15:24one hex digit is 16 different things
  454. 15:26we've seen that before
  455. 15:28two hex digits okay here we go two hex
  456. 15:30digits how many things can i do
  457. 15:32if you remember before zero to zero zero
  458. 15:35to f
  459. 15:36that's that's that's two hex digits well
  460. 15:38what's ff let's do the math
  461. 15:40oh it's 255. starting from zero that
  462. 15:43means 256 things
  463. 15:44okay so or n hex digits is
  464. 15:4816 to the n there's another way to think
  465. 15:49about that now
  466. 15:51turns out back in the days of thinking
  467. 15:54of making displays
  468. 15:55making computer displays okay they
  469. 15:57realized that
  470. 15:59we need just about eight digits eight
  471. 16:01digits eight bits
  472. 16:02to represent a single color partly
  473. 16:04because the human eye can't see more
  474. 16:05than if i had
  475. 16:06not by the way they now have high-end
  476. 16:08tvs that have more of those bits which
  477. 16:10is interesting because they can do
  478. 16:10dynamic range there's a long longer
  479. 16:12conversation there
  480. 16:13but the point of this is early tvs used
  481. 16:16eight bits for each of the red
  482. 16:18green and blue channels they concatenate
  483. 16:20them together to make a 24-bit
  484. 16:22color you need to know this for your
  485. 16:24first project
  486. 16:25let's see how that is illusion yeah
  487. 16:30so zero to 255 red zero 255
  488. 16:34green 55 blue you concatenate them
  489. 16:37together
  490. 16:38what you get is six hexadecimal digits
  491. 16:42and that's a color and if you've ever
  492. 16:44seen web programming or seen some color
  493. 16:47on a mac
  494. 16:47by the way i could go rogue and show you
  495. 16:49this this is probably we'll show you
  496. 16:50this in a second
  497. 16:51this is a color represented as six
  498. 16:55hexadecimal digits i'm gonna go rogue
  499. 16:57because i love doing this demo
  500. 16:59here we go i love this demo and the show
  501. 17:02keep my imitation discovery watch this
  502. 17:04so here we go ready apple
  503. 17:06system preferences desktop and screen
  504. 17:09saver
  505. 17:11desktop
  506. 17:15i can choose a color i can customize the
  507. 17:18color there's a long long way to get
  508. 17:20there
  509. 17:20i could have done this i could have done
  510. 17:21this by the way in powerpoint
  511. 17:25look at this this is rgb sliders
  512. 17:30that and here is the hex value so all
  513. 17:33white
  514. 17:34is all f's if i
  515. 17:37take these values down look at this
  516. 17:39watch how everything changes color
  517. 17:41as i move this color around watch this
  518. 17:45ff000 is all red
  519. 17:48huh with the thing if i add this color
  520. 17:51in
  521. 17:53ffff00 it's yellow
  522. 17:56is that cool so i can now adjust this
  523. 17:58and play with this and i encourage you
  524. 17:59to
  525. 18:00find one of these things one of these
  526. 18:01tools on the web to this
  527. 18:03to play with the colors to see actually
  528. 18:04colors here's d0367f
  529. 18:08uh as a color here on the bottom pretty
  530. 18:12cool
  531. 18:14which base do we use now you've got me
  532. 18:15six guys which one do i use well decimal
  533. 18:17is obviously great for humans especially
  534. 18:19when doing arithmetic we know how to do
  535. 18:20that very easily
  536. 18:21hexadecimal terrible for arithmetic just
  537. 18:24terrible
  538. 18:25but if you're looking at a string of
  539. 18:26binary digits i could either give you
  540. 18:28a crazy long number by digits or i could
  541. 18:30compact them down to a hexadecimal
  542. 18:32equivalent by the way would you prefer
  543. 18:33to give you
  544. 18:34that six hexadecimal digit color or 24
  545. 18:38bits you don't want the 24 bits right
  546. 18:40so i don't want that in binary
  547. 18:43what computers use you're going to be
  548. 18:45able to do multiplication division
  549. 18:47subtraction all the operations you think
  550. 18:49of in all the numbers computers always
  551. 18:51use binary because that's what they can
  552. 18:52do
  553. 18:52we'll talk about that a little later in
  554. 18:54the class transistors only know two
  555. 18:56states on or off
  556. 18:57current flowing or not flowing so
  557. 18:58they're going to use binary because of
  558. 18:59that
  559. 19:01regardless of how a number is written 32
  560. 19:04base 10
  561. 19:04or 32 base 1 0
  562. 19:07or 0x 20 or 1 0
  563. 19:110 0 000 base 2 or 0b1000
  564. 19:16they represent the same number those are
  565. 19:18all numerals
  566. 19:19representing the same number we'll talk
  567. 19:20about numerals in the next next video
  568. 19:23please do use the subscripts or the zero
  569. 19:25x or the zero b to precede your number
  570. 19:27so it's not ambiguous
  571. 19:29the computer knows it too this is really
  572. 19:32cool actually
  573. 19:33here's a little piece of c code we're
  574. 19:34gonna see in the next lecture but check
  575. 19:36this out i say 1 2 3 4 is my
  576. 19:38number right base 10 okay ten
  577. 19:42and i say let's just print this out so i
  578. 19:44print this out in percent d
  579. 19:45for you can see this here in percent d
  580. 19:48for
  581. 19:49decimal percent d
  582. 19:52percent x and percent o for octal
  583. 19:55base eight what does it print
  584. 19:58124 yeah that's good what else is a
  585. 20:02print
  586. 20:034d2 this is a problem
  587. 20:06it doesn't proceed with 0x or have a
  588. 20:08subscript 16.
  589. 20:10this is bad this means if it were like
  590. 20:12let's say let's say this number was 16
  591. 20:14it represents one zero and you wouldn't
  592. 20:15know what base it is
  593. 20:16so you better add the zero x yourself
  594. 20:18when you're printing it to percent x
  595. 20:20you got that good percent oh well how
  596. 20:22does it do percent oh it turns out that
  597. 20:24the way we do the great computers do
  598. 20:25octal is you
  599. 20:26lead at a leading zero it's a little
  600. 20:28ambiguous because you can always have a
  601. 20:29leading zero
  602. 20:30but by having a leading zero it tells
  603. 20:32the computer it's going to be octal
  604. 20:33we'll see that as we put these numbers
  605. 20:35in
  606. 20:36i can also go the other way watch this i
  607. 20:39can say
  608. 20:40pass the hexadecimal number in look at
  609. 20:43this i can
  610. 20:43hard code a hexadecimal number in by
  611. 20:46saying 0x
  612. 20:47if i say percent d that says convert it
  613. 20:49to decimal what does it give me
  614. 20:50one two three four is that cool same
  615. 20:53thing
  616. 20:54zero b some huge thing percent d
  617. 20:57converts it binary
  618. 20:58to decimal and here's my octal number
  619. 21:02preceded by a zero and here's percent d
  620. 21:04and we get one two three four for all of
  621. 21:06them
  622. 21:06isn't that cool so i just took these
  623. 21:08numbers here and put them there
  624. 21:10all right we're done with the series of
  625. 21:12we're done with this lecture
  626. 21:14the next lecture we're going to talk
  627. 21:15about how to represent
  628. 21:17negative numbers positive numbers in a
  629. 21:19more general way number representation
  630. 21:21we'll see you there

About this transcript

This page contains the full transcript of [CS61C FA20] Lecture 02.2 - Number Representation: Conversions by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 4,028 words across 630 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.