/
Lecture 02 Bits, Bytes, and Integers.ass
1323 lines (1320 loc) · 137 KB
/
Lecture 02 Bits, Bytes, and Integers.ass
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
[Script Info]
; Script generated by Aegisub r8942
; http://www.aegisub.org/
Title: Default Aegisub file
ScriptType: v4.00+
WrapStyle: 0
ScaledBorderAndShadow: yes
YCbCr Matrix: TV.601
PlayResX: 1280
PlayResY: 720
[Aegisub Project Garbage]
Last Style Storage: zh
Audio File: ../../../../Desktop/csapp/Lecture 02 Bits, Bytes, and Integers.mp4
Video File: ../../../../Desktop/csapp/Lecture 02 Bits, Bytes, and Integers.mp4
Video AR Mode: 4
Video AR Value: 1.777778
Video Zoom Percent: 1.000000
Scroll Position: 1140
Active Line: 1149
Video Position: 112259
[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Chinese,Noto Sans CJK SC Black,40,&H00FFFF00,&H00FFFFFF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,1.2,1.2,2,10,10,10,1
Style: English,Noto Sans CJK SC Black,30,&H00FFFFFF,&H00412A2C,&H00412A2C,&H00412A2C,0,0,0,0,100,100,0,0,1,1.5,1.2,2,10,10,10,1
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:00.00,0:00:04.68,English,,0,0,0,,I see a lot of people figure it out to come early so good see you
Dialogue: 0,0:00:00.00,0:00:04.68,Chinese,,0,0,0,,我看到很多人很早就来了,很高兴见到你们
Dialogue: 0,0:00:05.38,0:00:08.80,English,,0,0,0,,So as you recall,my name is Randy Bryant
Dialogue: 0,0:00:05.38,0:00:08.80,Chinese,,0,0,0,,如你们所知,我的名字是 Randal E. Bryant
Dialogue: 0,0:00:08.80,0:00:12.36,English,,0,0,0,,And I'm co-instructor of this course along with Dave Hallaron
Dialogue: 0,0:00:08.80,0:00:12.36,Chinese,,0,0,0,,我将和 Dave O'Hallaron 合作讲授本门课程
Dialogue: 0,0:00:12.80,0:00:22.66,English,,0,0,0,,And for the next couple lectures the first part of this course really will be talking about a sort of data representations
Dialogue: 0,0:00:12.80,0:00:22.66,Chinese,,0,0,0,,接下来的几次课,我们主要讨论课程的第一部分数据的表示
Dialogue: 0,0:00:22.66,0:00:28.30,English,,0,0,0,,In particular how numbers are represented in different forms and some of the properties and you saw that
Dialogue: 0,0:00:22.66,0:00:28.30,Chinese,,0,0,0,,特别是数字怎样以不同形式展示和它们一些对应的属性,你们会看到这些性质
Dialogue: 0,0:00:29.02,0:00:31.84,English,,0,0,0,,When I talked last week I showed you things like
Dialogue: 0,0:00:29.02,0:00:31.84,Chinese,,0,0,0,,上周的课上,我给你们展示过一些事情像
Dialogue: 0,0:00:31.84,0:00:36.38,English,,0,0,0,,You can multiply some numbers together that are positive and get negative result
Dialogue: 0,0:00:31.84,0:00:36.38,Chinese,,0,0,0,,你可以将一些正数相乘得到负数结果
Dialogue: 0,0:00:36.38,0:00:41.46,English,,0,0,0,,So what we want to understand is what is the bit level representation of numbers
Dialogue: 0,0:00:36.38,0:00:41.46,Chinese,,0,0,0,,所以我们需要了解是数字的位级表示
Dialogue: 0,0:00:41.90,0:00:47.28,English,,0,0,0,,And how does that affect some of the properties you have when you operate them on
Dialogue: 0,0:00:41.90,0:00:47.28,Chinese,,0,0,0,,以及当你操作它们时,会对数字的其他属性有怎样的影响
Dialogue: 0,0:00:47.28,0:00:51.12,English,,0,0,0,, and especially looking at the corner cases when things overflow
Dialogue: 0,0:00:47.28,0:00:51.12,Chinese,,0,0,0,,还有要特别关注临界条件当发生溢出时
Dialogue: 0,0:00:51.50,0:00:54.08,English,,0,0,0,,We sort of don't do what, you might expect them to do
Dialogue: 0,0:00:51.50,0:00:54.08,Chinese,,0,0,0,,哪些我们不能做,哪些你期望它们实现
Dialogue: 0,0:00:55.04,0:00:57.44,English,,0,0,0,, So we'll start off with very basic stuff of
Dialogue: 0,0:00:55.04,0:00:57.44,Chinese,,0,0,0,,所以我们从非常基本的东西开始
Dialogue: 0,0:00:57.44,0:01:03.84,English,,0,0,0,,How numbers is represented especially integer valued numbers are represented in bits
Dialogue: 0,0:00:57.44,0:01:03.84,Chinese,,0,0,0,,如何表示数字,尤其是整数值的位级表示
Dialogue: 0,0:01:05.82,0:01:13.72,English,,0,0,0,,Um so I think you pretty well figured out in this world that the whole digital world is sort of based on on binary values
Dialogue: 0,0:01:05.82,0:01:13.72,Chinese,,0,0,0,,恩,我觉得你们能很好的掌握基于二进制的数字世界
Dialogue: 0,0:01:14.48,0:01:21.98,English,,0,0,0,,And that wasn't always the case I mean since humans have ten fingers and ten toes
Dialogue: 0,0:01:14.48,0:01:21.98,Chinese,,0,0,0,,但二进制并不总是适用,因为人类有十个手指和十个脚趾
Dialogue: 0,0:01:22.26,0:01:25.04,English,,0,0,0,,A lot of the world was based on the decimal system
Dialogue: 0,0:01:22.26,0:01:25.04,Chinese,,0,0,0,,世界上的很多地方都是基于十进制的
Dialogue: 0,0:01:25.52,0:01:38.28,English,,0,0,0,,And it was really only and in fact the first electronic computer the ENIAC built in University of Pennsylvania basically encoded did all of its arithmetic using base ten
Dialogue: 0,0:01:25.52,0:01:38.28,Chinese,,0,0,0,,实际上只有宾夕法尼亚大学建立的第一台电子计算机 ENIAC 使用十进制进行了算术运算
Dialogue: 0,0:01:38.60,0:01:42.82,English,,0,0,0,,They had ten vacuum tubes per digit they wanted to represent
Dialogue: 0,0:01:38.60,0:01:42.82,Chinese,,0,0,0,,他们使用 10 个电子管来表示每个数字
Dialogue: 0,0:01:43.36,0:01:50.74,English,,0,0,0,,So they basically turned on or off those tubes to represent which of the ten possible digits you could want
Dialogue: 0,0:01:43.36,0:01:50.74,Chinese,,0,0,0,,所以他们通过控制电子管的开关来表示 10 个数字中的其中一个
Dialogue: 0,0:01:51.18,0:01:56.26,English,,0,0,0,,And it really didn't come to people until later than that
Dialogue: 0,0:01:51.18,0:01:56.26,Chinese,,0,0,0,,十进制使用一些时间之后才使用二进制
Dialogue: 0,0:01:56.52,0:02:01.58,English,,0,0,0,,So that's 1948 that they really should just think about base two for everything
Dialogue: 0,0:01:56.52,0:02:01.58,Chinese,,0,0,0,,1948年,他们应该考虑到了使用二进制构建一切
Dialogue: 0,0:02:04.06,0:02:14.00,English,,0,0,0,,And the reason why bits are great is in the digital world you can sort of take what otherwise an analog signal and quantify it
Dialogue: 0,0:02:04.06,0:02:14.00,Chinese,,0,0,0,,比特之所以伟大的原因是在数字世界中你可以采取其他方式的模拟信号对其进行量化
Dialogue: 0,0:02:14.36,0:02:17.56,English,,0,0,0,, And just say I'm going to say that one range of values
Dialogue: 0,0:02:14.36,0:02:17.56,Chinese,,0,0,0,,接下来我是用一组范围值来说明
Dialogue: 0,0:02:17.56,0:02:21.18,English,,0,0,0,, Let's say it's a low voltage I'm going to call that a zero
Dialogue: 0,0:02:17.56,0:02:21.18,Chinese,,0,0,0,,假如低电压表示 0
Dialogue: 0,0:02:21.46,0:02:24.52,English,,0,0,0,,And a high range of values I'm going to call it a one
Dialogue: 0,0:02:21.46,0:02:24.52,Chinese,,0,0,0,,我用某个高电压区间表示 1
Dialogue: 0,0:02:24.98,0:02:31.18,English,,0,0,0,, And if there's noise or imperfections in the circuit or anything going on
Dialogue: 0,0:02:24.98,0:02:31.18,Chinese,,0,0,0,,如果电路中存在噪音或不完善之地方,或者其他干扰
Dialogue: 0,0:02:31.76,0:02:37.78,English,,0,0,0,,As long as that doesn't exceed these bit these thresholds you've set up
Dialogue: 0,0:02:31.76,0:02:37.78,Chinese,,0,0,0,,只要不超过你设定的这些阈值
Dialogue: 0,0:02:38.18,0:02:40.38,English,,0,0,0,,Then you'll get a nice clean signal out of it
Dialogue: 0,0:02:38.18,0:02:40.38,Chinese,,0,0,0,,你就会得到一个很清晰的信号
Dialogue: 0,0:02:40.38,0:02:45.06,English,,0,0,0,,And that's the main advantage of digital processing over analog processing
Dialogue: 0,0:02:40.38,0:02:45.06,Chinese,,0,0,0,,这是数字处理相比模拟处理的主要优势
Dialogue: 0,0:02:46.80,0:02:50.10,English,,0,0,0,, And so that's sort of at the core why everything we do
Dialogue: 0,0:02:46.80,0:02:50.10,Chinese,,0,0,0,,这也是我们所做的一切的核心
Dialogue: 0,0:02:50.10,0:02:52.14,English,,0,0,0,, And especially for storing information
Dialogue: 0,0:02:50.10,0:02:52.14,Chinese,,0,0,0,,特别是对于信息存储来说,它更容易存储
Dialogue: 0,0:02:52.18,0:03:00.10,English,,0,0,0,,It turns out it's much easier to store one bit of information or a digital value than it is to store an analog value
Dialogue: 0,0:02:52.18,0:03:00.10,Chinese,,0,0,0,,事实证明,存储一位信息或一个数字值比存储一个模拟值要容易得多
Dialogue: 0,0:03:02.10,0:03:09.28,English,,0,0,0,,And sorry this kind of slides went a little crazy on animations
Dialogue: 0,0:03:02.10,0:03:09.28,Chinese,,0,0,0,,(对不起,这个幻灯片的动画做的有点“疯狂”)
Dialogue: 0,0:03:09.56,0:03:15.42,English,,0,0,0,,So the point is that we represent all the numbers in a computer as sets of bits
Dialogue: 0,0:03:09.56,0:03:15.42,Chinese,,0,0,0,,我们在计算机中使用比特位来表示所有数字
Dialogue: 0,0:03:15.42,0:03:18.24,English,,0,0,0,,And I think you generally understand that fairly well
Dialogue: 0,0:03:15.42,0:03:18.24,Chinese,,0,0,0,,我认为你们大多都非常了解
Dialogue: 0,0:03:18.68,0:03:23.98,English,,0,0,0,,And so of course the familiar binary representation of integers which we'll go over today
Dialogue: 0,0:03:18.68,0:03:23.98,Chinese,,0,0,0,,所以我们今天将要讨论使用熟悉的二进制表示整数
Dialogue: 0,0:03:24.34,0:03:32.87,English,,0,0,0,, Just uses a bit position for each power of two we can also represent values that are fractional
Dialogue: 0,0:03:24.34,0:03:32.87,Chinese,,0,0,0,,使用比特位对应的 2 的幂我们可以表示分数
Dialogue: 0,0:03:32.96,0:03:35.26,English,,0,0,0,,And we'll talk about that a week from today
Dialogue: 0,0:03:32.96,0:03:35.26,Chinese,,0,0,0,,我们将从今天开始讨论这个问题
Dialogue: 0,0:03:35.26,0:03:41.04,English,,0,0,0,,When we do floating-point numbers where what you do is to the right of the binary point
Dialogue: 0,0:03:35.26,0:03:41.04,Chinese,,0,0,0,,当我们处理浮点数时,我们要怎么处理小数点右边的数字
Dialogue: 0,0:03:41.18,0:03:46.60,English,,0,0,0,,So this is no longer a decimal point it's a binary point
Dialogue: 0,0:03:41.18,0:03:46.60,Chinese,,0,0,0,,所以这不再是一个十进制的小数点,它是一个二进制的小数点
Dialogue: 0,0:03:47.20,0:03:52.44,English,,0,0,0,,And so something to the left of that would have a weight 2^0
Dialogue: 0,0:03:47.20,0:03:52.44,Chinese,,0,0,0,,小数点左边第一位的权重是 2^0
Dialogue: 0,0:03:53.84,0:03:56.62,English,,0,0,0,,And the next one over would have weight 2^1
Dialogue: 0,0:03:53.84,0:03:56.62,Chinese,,0,0,0,,再向左一位的权重是 2^1
Dialogue: 0,0:03:57.04,0:04:03.88,English,,0,0,0,,But what you do is as you go to the right that adds weight 2^-1,2^-2
Dialogue: 0,0:03:57.04,0:04:03.88,Chinese,,0,0,0,,但是当你处理小数点右边的数字时它们增加的权重是 2^-1, 2^-2
Dialogue: 0,0:04:03.88,0:04:10.34,English,,0,0,0,, In other words this is 1,this is 2, this is 1/2 and this is 1/4
Dialogue: 0,0:04:03.88,0:04:10.34,Chinese,,0,0,0,,换句话说,这是 1,这是 2,这是 1/2,这是 1/4
Dialogue: 0,0:04:11.44,0:04:15.70,English,,0,0,0,,So we can represent just like you do the decimal representation of fractions
Dialogue: 0,0:04:11.44,0:04:15.70,Chinese,,0,0,0,,所以我们可以使用这样的方式表示分数,就像分数的十进制表示一样
Dialogue: 0,0:04:16.06,0:04:18.44,English,,0,0,0,,We can do the binary representation of fractions
Dialogue: 0,0:04:16.06,0:04:18.44,Chinese,,0,0,0,,我们可以使用二进制表示分数
Dialogue: 0,0:04:18.44,0:04:22.22,English,,0,0,0,, And that's the core of floating-point number of representations
Dialogue: 0,0:04:18.44,0:04:22.22,Chinese,,0,0,0,,这是二进制表示浮点数的核心思想
Dialogue: 0,0:04:23.94,0:04:35.06,English,,0,0,0,,And so it gets very annoying if you have say 32 or even 64-bit numbers to be writing the strings of 1 and 0 out
Dialogue: 0,0:04:23.94,0:04:35.06,Chinese,,0,0,0,,所以如果你见过数字写成 32 位甚至 64 位的 1 和 0 的字符串,那么它会变得非常烦人
Dialogue: 0,0:04:35.42,0:04:45.54,English,,0,0,0,,And so what we use,and what's become largely the most common is to group collections of 4bits at a time into
Dialogue: 0,0:04:35.42,0:04:45.54,Chinese,,0,0,0,,所以我们通常将 4 比特的数据集合分组
Dialogue: 0,0:04:45.98,0:04:50.90,English,,0,0,0,,And then represent that in base 16 or what's known as hexadecimal representation
Dialogue: 0,0:04:45.98,0:04:50.90,Chinese,,0,0,0,,然后用十六进制表示
Dialogue: 0,0:04:51.28,0:04:56.12,English,,0,0,0,, Using the letters A through F as values 10 through 15
Dialogue: 0,0:04:51.28,0:04:56.12,Chinese,,0,0,0,,使用字母 A 到 F 作为值 10 到 15
Dialogue: 0,0:04:56.12,0:05:00.78,English,,0,0,0,,And you'll spend a lot of time staring at hex decimal numbers this year
Dialogue: 0,0:04:56.12,0:05:00.78,Chinese,,0,0,0,,本学年你将会花费很多时间在十六进制上
Dialogue: 0,0:05:01.10,0:05:05.66,English,,0,0,0,,And you'll get pretty good at being able to look at a hex number and just write it out in binary
Dialogue: 0,0:05:01.10,0:05:05.66,Chinese,,0,0,0,,然后当你看到一个十六进制数字你就可以很快的写出它的二进制表示
Dialogue: 0,0:05:06.20,0:05:09.82,English,,0,0,0,,The way I do it just to tell you is
Dialogue: 0,0:05:06.20,0:05:09.82,Chinese,,0,0,0,,我这样做是为了告诉你们一个技巧
Dialogue: 0,0:05:10.56,0:05:22.74,English,,0,0,0,,I mean I've got the values from 0 to 9 wired down pretty well
Dialogue: 0,0:05:10.58,0:05:22.74,Chinese,,0,0,0,,我的意思是我很容易获得从 0 到 9 的二进制表示
Dialogue: 0,0:05:24.10,0:05:28.90,English,,0,0,0,,And then I keep track of a few special cases 1010 is A
Dialogue: 0,0:05:24.10,0:05:28.90,Chinese,,0,0,0,,然后我按照这个规律推导 1010 是 A
Dialogue: 0,0:05:29.78,0:05:37.94,English,,0,0,0,,1100 is C and 1111 is F
Dialogue: 0,0:05:29.78,0:05:37.94,Chinese,,0,0,0,,1100 是 C,1111 是 F
Dialogue: 0,0:05:39.00,0:05:45.46,English,,0,0,0,, And for B,D and E I kind of interpolate between those
Dialogue: 0,0:05:39.00,0:05:45.46,Chinese,,0,0,0,,而 B,D 和 E 在这些值之间
Dialogue: 0,0:05:45.46,0:05:49.10,English,,0,0,0,,So if you want to develop that skill that's the way you can do it
Dialogue: 0,0:05:45.46,0:05:49.10,Chinese,,0,0,0,,所以如果你想训练快速转化二进制,你可以尝试这种方法
Dialogue: 0,0:05:49.10,0:05:54.26,English,,0,0,0,,...and we learn HDMI connector that we can got here?...
Dialogue: 0,0:05:49.10,0:05:54.26,Chinese,,0,0,0,,... 我那们能获得有关 HDMI 的神马知识么(学生提问)...
Dialogue: 0,0:05:54.48,0:05:57.24,English,,0,0,0,,-No,I don't think there's any connector here. -no
Dialogue: 0,0:05:54.48,0:05:57.24,Chinese,,0,0,0,,-不,我不认为这里有任何联系 -没有
Dialogue: 0,0:06:03.36,0:06:06.68,English,,0,0,0,, So that's something you're going to end up wanting to be able to do
Dialogue: 0,0:06:03.36,0:06:06.68,Chinese,,0,0,0,,所以这就是你希望最终能够做到的事情
Dialogue: 0,0:06:08.08,0:06:10.74,English,,0,0,0,,So in C we don't...
Dialogue: 0,0:06:08.08,0:06:10.74,Chinese,,0,0,0,,所以在 C 语言中,我们不希望
Dialogue: 0,0:06:12.14,0:06:18.30,English,,0,0,0,,In most declarations you don't actually are told exactly how many bytes
Dialogue: 0,0:06:12.14,0:06:18.30,Chinese,,0,0,0,,实际上在大多数声明中你并不能被准确告知(变量有)多少字节
Dialogue: 0,0:06:18.30,0:06:20.30,English,,0,0,0,,A byte is 8 bits
Dialogue: 0,0:06:18.30,0:06:20.30,Chinese,,0,0,0,,一个字节是由 8 个比特组成
Dialogue: 0,0:06:20.96,0:06:23.14,English,,0,0,0,,Each data value is represented as
Dialogue: 0,0:06:20.96,0:06:23.14,Chinese,,0,0,0,,每种数据都是由字节组成
Dialogue: 0,0:06:23.52,0:06:30.46,English,,0,0,0,,And that's partly C was designed actually back when microprocessors only had 16-bit words
Dialogue: 0,0:06:23.52,0:06:30.46,Chinese,,0,0,0,,这部分是 C 的设计时,当时微处理器实际上只有 16 位字长
Dialogue: 0,0:06:30.46,0:06:32.38,English,,0,0,0,, It was actually before microprocessors
Dialogue: 0,0:06:30.46,0:06:32.38,Chinese,,0,0,0,,它实际上是在微处理器之前
Dialogue: 0,0:06:32.90,0:06:40.20,English,,0,0,0,, So 16-bit words were a fairly standard and over time that's expanded from 16 to 32 to now 64
Dialogue: 0,0:06:32.90,0:06:40.20,Chinese,,0,0,0,,所以 16 位字长是一个相当的标准,随着时间的推移,它从 16 位扩展到 32 位,现在是 64 位
Dialogue: 0,0:06:40.70,0:06:44.36,English,,0,0,0,,And so C rather than a sort of an advanced thing
Dialogue: 0,0:06:40.70,0:06:44.36,Chinese,,0,0,0,,所以 C 并不是一种先进的东西
Dialogue: 0,0:06:44.36,0:06:49.34,English,,0,0,0,,Here is how many bytes every value will have has these slightly ambiguous terms
Dialogue: 0,0:06:44.36,0:06:49.34,Chinese,,0,0,0,,这给出了每种值有多少字节,还有些含糊不清的术语
Dialogue: 0,0:06:49.84,0:06:53.20,English,,0,0,0,, That vary actually from one machine to the next
Dialogue: 0,0:06:49.84,0:06:53.20,Chinese,,0,0,0,,这些值从一台机器到另一台机器实际上有所不同
Dialogue: 0,0:06:55.26,0:07:01.00,English,,0,0,0,,And if you're a very careful C programmer you have to anticipate that some
Dialogue: 0,0:06:55.26,0:07:01.00,Chinese,,0,0,0,,如果你是一个仔细的 C 程序员,你必须预料到一些情况
Dialogue: 0,0:07:01.44,0:07:09.80,English,,0,0,0,,But what won't deal with is x86-64 is the class of machines will be working with exclusively this term
Dialogue: 0,0:07:01.44,0:07:09.80,Chinese,,0,0,0,,不过本学期我们只关注 X86-64 位机器,16 位,32 位我们不会涉及
Dialogue: 0,0:07:10.10,0:07:13.22,English,,0,0,0,,And so you can see that when you declare something to be a care
Dialogue: 0,0:07:10.10,0:07:13.22,Chinese,,0,0,0,,所以你可以看到,当你声明一些关键词时需要特别小心
Dialogue: 0,0:07:13.80,0:07:17.68,English,,0,0,0,, Sometimes people call it a char that's a 1 byte value
Dialogue: 0,0:07:13.80,0:07:17.68,Chinese,,0,0,0,,有时候人们称一个 char 类型的值是 1 个字节
Dialogue: 0,0:07:17.88,0:07:20.66,English,,0,0,0,,A short is 16 bits
Dialogue: 0,0:07:17.88,0:07:20.66,Chinese,,0,0,0,,short 是 16 位
Dialogue: 0,0:07:21.58,0:07:29.76,English,,0,0,0,,An int is 32 and if you want to get all 64 bits you have to declare it to be a long
Dialogue: 0,0:07:21.58,0:07:29.76,Chinese,,0,0,0,,一个 int 是 32 位,如果你想获得所有的都是 64 位,你必须声明它是一个 long
Dialogue: 0,0:07:32.20,0:07:39.34,English,,0,0,0,,And then again there's two different representations of floating-point there's 4 byte or 32 bit of floating-point numbers and 64 bit
Dialogue: 0,0:07:32.20,0:07:39.34,Chinese,,0,0,0,,同样,浮点表示也有两种不同表示方法,4 个字节( 32 位)和 64 位两种浮点数
Dialogue: 0,0:07:39.84,0:07:47.48,English,,0,0,0,,There's also a slightly obscure holdover from ancient days of floating-point
Dialogue: 0,0:07:39.84,0:07:47.48,Chinese,,0,0,0,,早期的浮点运算中也有一个稍微模糊的定义
Dialogue: 0,0:07:47.48,0:07:54.24,English,,0,0,0,,Where there's a special representation in Intel machines that uses a 10 bytes or 80 bit representation
Dialogue: 0,0:07:47.48,0:07:54.24,Chinese,,0,0,0,,英特尔机器中使用 10 字节或 80 位的特殊表示
Dialogue: 0,0:07:54.70,0:08:03.68,English,,0,0,0,, And when you use that on a 64-bit machine they sort of waste an extra 6 bytes out of that
Dialogue: 0,0:07:54.70,0:08:03.68,Chinese,,0,0,0,,当你在 64 位机器上使用它时,它们会浪费额外的 6 个字节
Dialogue: 0,0:08:03.68,0:08:07.88,English,,0,0,0,,So that everything is aligned in 16 byte increments
Dialogue: 0,0:08:03.68,0:08:07.88,Chinese,,0,0,0,,这样一切都以 16 字节为增量对齐
Dialogue: 0,0:08:08.80,0:08:17.86,English,,0,0,0,, The other thing and this is an important feature is any address is defined to be the sort of the word size of the machine
Dialogue: 0,0:08:08.80,0:08:17.86,Chinese,,0,0,0,,另一件事,这是一个重要的功能是虚拟地址空间是由机器字长决定的
Dialogue: 0,0:08:17.86,0:08:25.98,English,,0,0,0,, When they say it's a 64-bit machine,what they really mean is that the addresses are 64-bit values or 8-byte values
Dialogue: 0,0:08:17.86,0:08:25.98,Chinese,,0,0,0,,当他们说这是一个 64 位机器时,他们的真正含义是这些地址是 64 位值或 8 字节值
Dialogue: 0,0:08:26.28,0:08:31.54,English,,0,0,0,,And that's different for example if you use a older machine a 32-bit machine
Dialogue: 0,0:08:26.28,0:08:31.54,Chinese,,0,0,0,,如果你使用较旧的机器和 32 位机器,情况就不同了
Dialogue: 0,0:08:31.56,0:08:34.06,English,,0,0,0,,Those will only be 32-bit addresses
Dialogue: 0,0:08:31.56,0:08:34.06,Chinese,,0,0,0,,那些只会是 32 位地址
Dialogue: 0,0:08:37.42,0:08:48.14,English,,0,0,0,,So the basis thing I imagine you've had this at some point of how do we then think about bits is based on boolean algebra
Dialogue: 0,0:08:37.42,0:08:48.14,Chinese,,0,0,0,,所以基础的事情是我们基于布尔代数来考虑位级运算
Dialogue: 0,0:08:48.40,0:08:55.14,English,,0,0,0,, Which is actually comes from the 1890s that a guy named George Boole
Dialogue: 0,0:08:48.40,0:08:55.14,Chinese,,0,0,0,,(布尔代数)源于 1890 年代的一个名叫 George Boole 的人(准确的是 1850 前后)
Dialogue: 0,0:08:55.38,0:09:02.44,English,,0,0,0,,Who recognized is sort of relation between what we'd call bits but they weren't called bits back then
Dialogue: 0,0:08:55.38,0:09:02.44,Chinese,,0,0,0,,发现比特之间的关系,但当时他们并不称之为比特
Dialogue: 0,0:09:02.98,0:09:08.76,English,,0,0,0,,0, 1 and logic are basically truth values in logic
Dialogue: 0,0:09:02.98,0:09:08.76,Chinese,,0,0,0,,0,1 是逻辑上最基础的值
Dialogue: 0,0:09:09.06,0:09:13.26,English,,0,0,0,,I thinking of an algebra sort of a structured set of operations
Dialogue: 0,0:09:09.06,0:09:13.26,Chinese,,0,0,0,,我想到了一系列结构化操作的代数
Dialogue: 0,0:09:13.26,0:09:19.08,English,,0,0,0,, You could apply that would capture some of the concepts that people assume in logic
Dialogue: 0,0:09:13.26,0:09:19.08,Chinese,,0,0,0,,你可以运用它来捕捉人们在逻辑中假设的一些概念
Dialogue: 0,0:09:19.56,0:09:24.14,English,,0,0,0,,So for example if we think of 1 being true and 0 being false
Dialogue: 0,0:09:19.56,0:09:24.14,Chinese,,0,0,0,,例如,如果我们认为 1 是真而 0 是假
Dialogue: 0,0:09:24.80,0:09:31.06,English,,0,0,0,,Then the and operation is true if both of the inputs the both of the arguments are true
Dialogue: 0,0:09:24.80,0:09:31.06,Chinese,,0,0,0,,然后,如果两个参数的两个输入均为真,则操作为真
Dialogue: 0,0:09:31.48,0:09:33.00,English,,0,0,0,,so we get this chart here
Dialogue: 0,0:09:31.48,0:09:33.00,Chinese,,0,0,0,,所以我们在这里得到这张图表
Dialogue: 0,0:09:33.00,0:09:38.86,English,,0,0,0,,Similarly the or operation is true if either input is true or 1
Dialogue: 0,0:09:33.00,0:09:38.86,Chinese,,0,0,0,,同样,如果任何一个输入为真或 1,则操作为真
Dialogue: 0,0:09:39.30,0:09:43.04,English,,0,0,0,,The NOT is just to flip the bit
Dialogue: 0,0:09:39.30,0:09:43.04,Chinese,,0,0,0,,NOT 只是为了翻转位
Dialogue: 0,0:09:43.42,0:09:49.36,English,,0,0,0,,And then the exclusive-or is what you get when you say it's one or the other but not both
Dialogue: 0,0:09:43.42,0:09:49.36,Chinese,,0,0,0,,然后异或是当你说它是相同为 0 相异为 1
Dialogue: 0,0:09:49.70,0:09:52.26,English,,0,0,0,, And so it has this representation
Dialogue: 0,0:09:49.70,0:09:52.26,Chinese,,0,0,0,,所以它有这种表示结果
Dialogue: 0,0:09:52.56,0:09:59.74,English,,0,0,0,, So just as a bit of history it was a master's degree student at MIT named Claude Shannon
Dialogue: 0,0:09:52.56,0:09:59.74,Chinese,,0,0,0,,回顾比特的历史,它是麻省理工学院的一位名为 Claude Shannon 的硕士生
Dialogue: 0,0:10:00.28,0:10:07.02,English,,0,0,0,, Who had taken a course in logic as an undergraduate at University of Michigan
Dialogue: 0,0:10:00.28,0:10:07.02,Chinese,,0,0,0,,他曾在密歇根大学攻读逻辑学课程的本科生
Dialogue: 0,0:10:07.80,0:10:12.86,English,,0,0,0,,And he was the one who made the connection between thinking about
Dialogue: 0,0:10:07.80,0:10:12.86,Chinese,,0,0,0,,而他是在思考之间建立联系的人
Dialogue: 0,0:10:12.86,0:10:20.34,English,,0,0,0,,This this what was at the time very obscure branch of something a rather of logic
Dialogue: 0,0:10:12.86,0:10:20.34,Chinese,,0,0,0,,这在当时是非常模糊的东西,而非逻辑
Dialogue: 0,0:10:20.52,0:10:24.30,English,,0,0,0,,And applying it to digital systems back in an era when they actually built
Dialogue: 0,0:10:20.52,0:10:24.30,Chinese,,0,0,0,,并将它应用到数字系统,回到他们实际构建的时代
Dialogue: 0,0:10:24.66,0:10:27.44,English,,0,0,0,, These things out of electromechanical noise
Dialogue: 0,0:10:24.66,0:10:27.44,Chinese,,0,0,0,,这些东西没有机电噪音
Dialogue: 0,0:10:28.12,0:10:36.88,English,,0,0,0,, And so his master's thesis is probably the most impactful master's thesis in the history of humankind
Dialogue: 0,0:10:28.12,0:10:36.88,Chinese,,0,0,0,,所以他的硕士论文可能是人类历史上最具影响力的硕士论文
Dialogue: 0,0:10:37.58,0:10:41.96,English,,0,0,0,,And he always wonder well what did they do before that then
Dialogue: 0,0:10:37.58,0:10:41.96,Chinese,,0,0,0,,他总是很好奇他们在那之前做了什么
Dialogue: 0,0:10:41.96,0:10:44.18,English,,0,0,0,,You know how do they even think about these things
Dialogue: 0,0:10:41.96,0:10:44.18,Chinese,,0,0,0,,你知道他们怎么看待这些事情
Dialogue: 0,0:10:44.72,0:10:49.84,English,,0,0,0,,Anyways the idea of applying this algebra then to bits is not
Dialogue: 0,0:10:44.72,0:10:49.84,Chinese,,0,0,0,,无论如何,将这个代数应用于位的想法不是
Dialogue: 0,0:10:50.40,0:10:54.34,English,,0,0,0,,Something that should have been true since the the world began
Dialogue: 0,0:10:50.40,0:10:54.34,Chinese,,0,0,0,,自从世界开始以来就理所应当的
Dialogue: 0,0:10:54.36,0:10:57.20,English,,0,0,0,, Something that's a relatively modern concept
Dialogue: 0,0:10:54.36,0:10:57.20,Chinese,,0,0,0,,这是一个相对现代的概念
Dialogue: 0,0:10:57.86,0:11:06.82,English,,0,0,0,,Now what's an important thing that might be less obvious is we can also do these over words
Dialogue: 0,0:10:57.86,0:11:06.82,Chinese,,0,0,0,,现在可能不那么明显的一件重要事情是,我们也可以用言语来做这些事情
Dialogue: 0,0:11:06.82,0:11:13.42,English,,0,0,0,,We can do these boolean operations where we apply them on each successive bit in that word
Dialogue: 0,0:11:06.82,0:11:13.42,Chinese,,0,0,0,,当我们操作连续的比特时,可以认为是对每个比特位使用布尔操做
Dialogue: 0,0:11:13.70,0:11:18.58,English,,0,0,0,,And these symbols we use the &, | and ~
Dialogue: 0,0:11:13.70,0:11:18.58,Chinese,,0,0,0,,我们使用 & | ~ 这些符号来操作
Dialogue: 0,0:11:18.80,0:11:22.54,English,,0,0,0,, are actually the ones that see use is to represent these operations
Dialogue: 0,0:11:18.80,0:11:22.54,Chinese,,0,0,0,,实际上是用来代表这些位操作
Dialogue: 0,0:11:23.16,0:11:28.46,English,,0,0,0,,And so again if we look at here the 1 is only if both of the values 1
Dialogue: 0,0:11:23.16,0:11:28.46,Chinese,,0,0,0,,如果我们再看这里,那么 (AND操作)1 只有当两个值都是 1
Dialogue: 0,0:11:28.98,0:11:33.38,English,,0,0,0,,And the for the OR for the AND for the one
Dialogue: 0,0:11:28.98,0:11:33.38,Chinese,,0,0,0,,相比与 AND,对于 OR 来说产生 1 的方式是
Dialogue: 0,0:11:33.72,0:11:36.02,English,,0,0,0,, OR its if either of them are 1
Dialogue: 0,0:11:33.72,0:11:36.02,Chinese,,0,0,0,,它们中的任何一个是 1
Dialogue: 0,0:11:36.58,0:11:40.46,English,,0,0,0,,The exclusive or if 1 is 1 and the other is zero
Dialogue: 0,0:11:36.58,0:11:40.46,Chinese,,0,0,0,,如果是异或,1 是由 1 和另外一个数 0 产生的
Dialogue: 0,0:11:40.58,0:11:43.74,English,,0,0,0,,And tilde is just to invert the bits of it
Dialogue: 0,0:11:40.58,0:11:43.74,Chinese,,0,0,0,,~(非)只是反转它的位
Dialogue: 0,0:11:43.74,0:11:49.16,English,,0,0,0,,So again we will spend a lot of time making use of the fact that in C
Dialogue: 0,0:11:43.74,0:11:49.16,Chinese,,0,0,0,,所以我们将花费大量的时间在 C 语言中使用并实现这些逻辑
Dialogue: 0,0:11:49.16,0:11:51.48,English,,0,0,0,,And this is one of the features to C that people like
Dialogue: 0,0:11:49.16,0:11:51.48,Chinese,,0,0,0,,人们喜欢的 C 特性之一就是
Dialogue: 0,0:11:51.78,0:11:57.16,English,,0,0,0,,is that you can do these sort of very low level of bit manipulations directly in the language
Dialogue: 0,0:11:51.78,0:11:57.16,Chinese,,0,0,0,,你可以直接在语言中执行这些低级别的位操作
Dialogue: 0,0:11:58.28,0:11:59.50,English,,0,0,0,,and um
Dialogue: 0,0:11:58.28,0:11:59.50,Chinese,,0,0,0,,嗯
Dialogue: 0,0:12:00.60,0:12:04.34,English,,0,0,0,,This actually turns out to be useful in practice
Dialogue: 0,0:12:00.60,0:12:04.34,Chinese,,0,0,0,,这实际上在实践中证明是有用的
Dialogue: 0,0:12:04.34,0:12:08.66,English,,0,0,0,, And it's sort of implicit of a way of representing sets of values
Dialogue: 0,0:12:04.34,0:12:08.66,Chinese,,0,0,0,,这是一种隐式的表示数值集合的方式
Dialogue: 0,0:12:08.76,0:12:13.12,English,,0,0,0,,So this example is a imagine we want to represent sets
Dialogue: 0,0:12:08.76,0:12:13.12,Chinese,,0,0,0,,所以这个例子是想象我们要表示集合
Dialogue: 0,0:12:13.78,0:12:18.40,English,,0,0,0,,Where the elements of the set are numbers ranging between 0 and 7
Dialogue: 0,0:12:13.78,0:12:18.40,Chinese,,0,0,0,,该集合由 0 到 7 之间的整数组成
Dialogue: 0,0:12:18.92,0:12:23.92,English,,0,0,0,,So 1 byte is enough to capture eight cases
Dialogue: 0,0:12:18.92,0:12:23.92,Chinese,,0,0,0,,所以 1 个字节足以表示 8 种情况
Dialogue: 0,0:12:24.22,0:12:29.00,English,,0,0,0,,And we'll just if we number the bits and we number them from right to left
Dialogue: 0,0:12:24.22,0:12:29.00,Chinese,,0,0,0,,我们只需要对这些位进行从右向左编号即可
Dialogue: 0,0:12:29.58,0:12:36.96,English,,0,0,0,,So this is bit 0 so that would represent whether or not the value 0 is an element of the set
Dialogue: 0,0:12:29.58,0:12:36.96,Chinese,,0,0,0,,所以第 0 位表示 0 是否是该集合的一个元素
Dialogue: 0,0:12:37.58,0:12:41.06,English,,0,0,0,,And similarly here you'll see 0,1,2,3
Dialogue: 0,0:12:37.58,0:12:41.06,Chinese,,0,0,0,,同样在这里你会看到 0,1,2,3
Dialogue: 0,0:12:41.06,0:12:47.84,English,,0,0,0,,So we're seeing that bit 3 being one here means 3 is an element of the set and so forth
Dialogue: 0,0:12:41.06,0:12:47.84,Chinese,,0,0,0,,我们看到第 3 位是 1,这意味着 3 是这个集合中的一个元素,等等
Dialogue: 0,0:12:48.40,0:12:52.30,English,,0,0,0,,and the
Dialogue: 0,0:12:48.40,0:12:52.30,Chinese,,0,0,0,,
Dialogue: 0,0:12:54.74,0:12:59.32,English,,0,0,0,,So the idea is then the AND operation becomes like set intersection
Dialogue: 0,0:12:54.74,0:12:59.32,Chinese,,0,0,0,,所以 AND(&) 操作变得像集合的交
Dialogue: 0,0:12:59.66,0:13:02.30,English,,0,0,0,, The OR operation becomes like set Union
Dialogue: 0,0:12:59.66,0:13:02.30,Chinese,,0,0,0,,OR(|)操作变得像集合的并
Dialogue: 0,0:13:02.66,0:13:08.70,English,,0,0,0,,And the X-OR operation is what's called symmetric difference
Dialogue: 0,0:13:02.66,0:13:08.70,Chinese,,0,0,0,,而异或(X-OR)操作就是所谓的对称差异
Dialogue: 0,0:13:11.40,0:13:14.84,English,,0,0,0,,And so these are actually and ~ is like set complement
Dialogue: 0,0:13:11.40,0:13:14.84,Chinese,,0,0,0,,所以实际上 〜 即为集合的补集
Dialogue: 0,0:13:14.86,0:13:18.28,English,,0,0,0,,So these are actually very common for example
Dialogue: 0,0:13:14.86,0:13:18.28,Chinese,,0,0,0,,这些实际上很常见
Dialogue: 0,0:13:18.54,0:13:27.80,English,,0,0,0,,There are operations you'll learn later when we look at a file I/O
Dialogue: 0,0:13:18.54,0:13:27.80,Chinese,,0,0,0,,这就是我们在文件 I/O 时将要学到的一些操作
Dialogue: 0,0:13:27.98,0:13:35.36,English,,0,0,0,,About I/O that you can track I want to know which set of possible inputs to the system
Dialogue: 0,0:13:27.98,0:13:35.36,Chinese,,0,0,0,,关于 I/O 你可以跟踪你想知道系统可能有哪些输入
Dialogue: 0,0:13:35.36,0:13:40.04,English,,0,0,0,,think of different network connections have an input ready for me to read
Dialogue: 0,0:13:35.36,0:13:40.04,Chinese,,0,0,0,,想想不同的网络连接有一个输入可供我阅读
Dialogue: 0,0:13:40.80,0:13:44.04,English,,0,0,0,,And there is a data structure that
Dialogue: 0,0:13:40.80,0:13:44.04,Chinese,,0,0,0,,并且有一个数据结构
Dialogue: 0,0:13:44.78,0:13:47.60,English,,0,0,0,,It's sort of hidden away among some C library calls
Dialogue: 0,0:13:44.78,0:13:47.60,Chinese,,0,0,0,,它可能隐藏在多个 C 语言库调用中
Dialogue: 0,0:13:47.60,0:13:52.20,English,,0,0,0,, But it basically is using exactly this representation about a thousand
Dialogue: 0,0:13:47.60,0:13:52.20,Chinese,,0,0,0,,但它基本上使用了大约一千个
Dialogue: 0,0:13:52.50,0:13:55.90,English,,0,0,0,,A bits worth of information to represent these sets
Dialogue: 0,0:13:52.50,0:13:55.90,Chinese,,0,0,0,,位来表示这些集合的信息
Dialogue: 0,0:13:56.54,0:14:00.18,English,,0,0,0,,And do manipulation on those sets so this is a very common
Dialogue: 0,0:13:56.54,0:14:00.18,Chinese,,0,0,0,,并且对这些设置进行操作,所以这是非常常见的
Dialogue: 0,0:14:00.48,0:14:05.48,English,,0,0,0,,And why do we use representation of sets in computer science
Dialogue: 0,0:14:00.48,0:14:05.48,Chinese,,0,0,0,,这就是为什么我们在计算机科学中使用集合表示
Dialogue: 0,0:14:07.98,0:14:15.68,English,,0,0,0,,so as I mentioned those are available directly in C the &,|, ~ and ^
Dialogue: 0,0:14:07.98,0:14:15.68,Chinese,,0,0,0,,所以我刚才提到那些可以直接在 C 语言中使用是&,|,~ 和 ^
Dialogue: 0,0:14:16.46,0:14:21.82,English,,0,0,0,,One thing that's really really important and that programmers screw it up all the time
Dialogue: 0,0:14:16.46,0:14:21.82,Chinese,,0,0,0,,有一件事情真的非常重要而且程序员总是把它搞砸
Dialogue: 0,0:14:21.82,0:14:31.12,English,,0,0,0,,Beginning programmers a lot and even experienced programmers from time to time is to mix up the & in the &&
Dialogue: 0,0:14:21.82,0:14:31.12,Chinese,,0,0,0,,很多初级程序员,有时甚至是经验丰富的程序员都会混淆 & 在 &&
Dialogue: 0,0:14:31.12,0:14:34.14,English,,0,0,0,,or the | and the ||
Dialogue: 0,0:14:31.12,0:14:34.14,Chinese,,0,0,0,,或 | 和 ||
Dialogue: 0,0:14:34.88,0:14:39.70,English,,0,0,0,,and the ~ versus the exclamation mark which is often pronounced bang
Dialogue: 0,0:14:34.88,0:14:39.70,Chinese,,0,0,0,,而 〜 与 ! (经常读作 "bang")混淆
Dialogue: 0,0:14:40.66,0:14:44.68,English,,0,0,0,,so and the reason
Dialogue: 0,0:14:40.66,0:14:44.68,Chinese,,0,0,0,,造成混淆原因是
Dialogue: 0,0:14:45.58,0:14:49.00,English,,0,0,0,, So obviously there's sort of a syntactic similarity
Dialogue: 0,0:14:45.58,0:14:49.00,Chinese,,0,0,0,,所以显然有句法相似之处
Dialogue: 0,0:14:49.00,0:14:51.60,English,,0,0,0,,And there's actually a somewhat of a semantic relation to that
Dialogue: 0,0:14:49.00,0:14:51.60,Chinese,,0,0,0,,而且实际上有一些与此有关的语义关系
Dialogue: 0,0:14:52.10,0:14:56.74,English,,0,0,0,, This is another kind of AND another kind of OR and another kind of NOT
Dialogue: 0,0:14:52.10,0:14:56.74,Chinese,,0,0,0,,这是另一种 AND 的另一种 OR 和另一种 NOT
Dialogue: 0,0:14:57.90,0:15:02.06,English,,0,0,0,,But if you mix and match these you're certainly going to have problems
Dialogue: 0,0:14:57.90,0:15:02.06,Chinese,,0,0,0,,但是,如果使用时混淆这些,你肯定会遇到问题
Dialogue: 0,0:15:02.66,0:15:11.10,English,,0,0,0,,So the || ones aren't thinking about bitwise operations through thinking about something that's either true or false period
Dialogue: 0,0:15:02.66,0:15:11.10,Chinese,,0,0,0,,所以人们不会认为 || 是位操作,而是会考虑一段时间内条件的真假
Dialogue: 0,0:15:12.18,0:15:17.48,English,,0,0,0,,And in that representation the number 0 is the thing that's false
Dialogue: 0,0:15:12.18,0:15:17.48,Chinese,,0,0,0,,在这个表示中,数字 0 是假
Dialogue: 0,0:15:17.48,0:15:21.70,English,,0,0,0,,And anything else any other bit pattern is considered to be true
Dialogue: 0,0:15:17.48,0:15:21.70,Chinese,,0,0,0,,而其他任何其比特表示的数字都被认为是真
Dialogue: 0,0:15:23.60,0:15:31.72,English,,0,0,0,,The other feature that the || give you is what's called early termination
Dialogue: 0,0:15:23.60,0:15:31.72,Chinese,,0,0,0,,|| 的另一个特点让你的调用提前终止
Dialogue: 0,0:15:32.86,0:15:37.56,English,,0,0,0,,So in particular if we do some examples
Dialogue: 0,0:15:32.86,0:15:37.56,Chinese,,0,0,0,,现在我们举一些特定的例子
Dialogue: 0,0:15:37.78,0:15:50.48,English,,0,0,0,,On the some hex pattern for 1, so this is a not a 0 and so that's considered true
Dialogue: 0,0:15:37.78,0:15:50.46,Chinese,,0,0,0,,产生 0x01 是因为非零数会被认为是真
Dialogue: 0,0:15:50.54,0:15:54.02,English,,0,0,0,,So the the bang of that the not of that is 0
Dialogue: 0,0:15:50.54,0:15:54.02,Chinese,,0,0,0,,而对这个值取“非”就是 0
Dialogue: 0,0:15:54.04,0:15:57.36,English,,0,0,0,,The same way if you have 0 the not event is 1
Dialogue: 0,0:15:54.04,0:15:57.36,Chinese,,0,0,0,,同样的,如果是 0,那么 “非”0 就是 1
Dialogue: 0,0:15:57.66,0:16:04.18,English,,0,0,0,,And if you apply bang to a number twice you'll get back a 1 unless it was 0
Dialogue: 0,0:15:57.66,0:16:04.18,Chinese,,0,0,0,,如果你对一个非零数应用两次 !,你会得到 1
Dialogue: 0,0:16:08.84,0:16:13.04,English,,0,0,0,,And then the same these patterns here
Dialogue: 0,0:16:08.84,0:16:13.04,Chinese,,0,0,0,,这里也是类似的情况
Dialogue: 0,0:16:13.44,0:16:18.30,English,,0,0,0,,The reason why this returns 1 is because it's considered two cases that are true
Dialogue: 0,0:16:13.44,0:16:18.30,Chinese,,0,0,0,,这里返回 1 的原因是这里的两个条件都是真
Dialogue: 0,0:16:19.88,0:16:24.50,English,,0,0,0,,So it's not doing bitwise operations it's just trying to create true and false
Dialogue: 0,0:16:19.88,0:16:24.50,Chinese,,0,0,0,,所以这不是位操作,而是判断“真”“假”
Dialogue: 0,0:16:24.50,0:16:29.28,English,,0,0,0,,It's interpreting arguments be there true or false and returning either true or false
Dialogue: 0,0:16:24.50,0:16:29.28,Chinese,,0,0,0,,它根据的参数的 “真”“假”,返回 “真” 或 “假”
Dialogue: 0,0:16:29.78,0:16:34.92,English,,0,0,0,,But when it returns true it returns one and not whatever number you happen to give
Dialogue: 0,0:16:29.78,0:16:34.92,Chinese,,0,0,0,,但是当它返回“真”时返回的是 1,而不是你给出的任何数字
Dialogue: 0,0:16:35.82,0:16:43.72,English,,0,0,0,,So obviously this is a very different operations than you have with the single versions of those and
Dialogue: 0,0:16:35.82,0:16:43.72,Chinese,,0,0,0,,显然这和位操作完全不同
Dialogue: 0,0:16:44.74,0:16:51.66,English,,0,0,0,,But it's easy just because you mentally slip or because you type something wrong to do the wrong thing
Dialogue: 0,0:16:44.74,0:16:51.66,Chinese,,0,0,0,,但是这种情况在你你一时疏忽,或者误操作时很容易出现
Dialogue: 0,0:16:52.18,0:16:56.22,English,,0,0,0,,But in particularly this early termination is something that of course people use a lot
Dialogue: 0,0:16:52.18,0:16:56.22,Chinese,,0,0,0,,特别是“提前终止”这种特性被很多人用到的时候
Dialogue: 0,0:16:56.74,0:17:01.04,English,,0,0,0,,If you want to make sure that you're not accessing a null pointer
Dialogue: 0,0:16:56.74,0:17:01.04,Chinese,,0,0,0,,如果你想确保你没有访问空指针
Dialogue: 0,0:17:01.04,0:17:05.68,English,,0,0,0,, You can test whether that's a null pointer first before accessing it
Dialogue: 0,0:17:01.04,0:17:05.68,Chinese,,0,0,0,,你可以在访问它之前先测试它是否为空指针
Dialogue: 0,0:17:05.68,0:17:11.18,English,,0,0,0,,And this if this is 0 or null then it will do the the dereferencing of null
Dialogue: 0,0:17:05.68,0:17:11.18,Chinese,,0,0,0,,如果这是 0 或 null,就能避免对 null 的引用
Dialogue: 0,0:17:12.12,0:17:15.44,English,,0,0,0,,So it's a fairly useful feature as well
Dialogue: 0,0:17:12.12,0:17:15.44,Chinese,,0,0,0,,所以这也是一个相当有用的功能
Dialogue: 0,0:17:15.66,0:17:21.38,English,,0,0,0,,So anyways just that's an aside at this level we're mostly looking at bits
Dialogue: 0,0:17:15.66,0:17:21.38,Chinese,,0,0,0,,所以无论如何,在这个层面上,我们大多数都是看比特
Dialogue: 0,0:17:21.38,0:17:24.62,English,,0,0,0,,But just as a programming no don't mix these up
Dialogue: 0,0:17:21.38,0:17:24.62,Chinese,,0,0,0,,但就像编程一样,不要混淆
Dialogue: 0,0:17:32.62,0:17:36.68,English,,0,0,0,,The other class of operations will make use of a lot our shifting
Dialogue: 0,0:17:32.62,0:17:36.68,Chinese,,0,0,0,,其他位操作中我们使用次数最多的就是位移
Dialogue: 0,0:17:37.08,0:17:42.24,English,,0,0,0,, Which again is not something that you normally sort of as beginning programmers think about too much
Dialogue: 0,0:17:37.08,0:17:42.24,Chinese,,0,0,0,,这不像很多初级程序员所思考的那样
Dialogue: 0,0:17:42.92,0:17:47.10,English,,0,0,0,,And if there's a curious feature that a left shifts are always the same
Dialogue: 0,0:17:42.92,0:17:47.10,Chinese,,0,0,0,,位移有一个奇怪的功能就是左移总是相同的
Dialogue: 0,0:17:47.10,0:17:49.20,English,,0,0,0,,But there's two different flavors of right shift
Dialogue: 0,0:17:47.10,0:17:49.20,Chinese,,0,0,0,,但是它有两种不同的右移方式
Dialogue: 0,0:17:49.62,0:17:53.72,English,,0,0,0,, And we'll see in a little bit later why there's two different flavors of right shift
Dialogue: 0,0:17:49.62,0:17:53.72,Chinese,,0,0,0,,稍后我们会看到为什么有两种不同的右移方式
Dialogue: 0,0:17:54.90,0:17:58.61,English,,0,0,0,,But um
Dialogue: 0,0:17:54.90,0:17:58.61,Chinese,,0,0,0,,但是
Dialogue: 0,0:17:59.00,0:18:03.22,English,,0,0,0,,The idea that of shifting is that you have some argument x
Dialogue: 0,0:17:59.00,0:18:03.22,Chinese,,0,0,0,,移位的思想是你有一个参数 x
Dialogue: 0,0:18:03.22,0:18:08.52,English,,0,0,0,,And you want to shift it some number of positions either to the left or to the right given by y
Dialogue: 0,0:18:03.22,0:18:08.52,Chinese,,0,0,0,,你想要将它的位置向左或向右移动 y 个位
Dialogue: 0,0:18:09.50,0:18:15.02,English,,0,0,0,,And so when you shift left you just fill in whatever value there was so you pick up the
Dialogue: 0,0:18:09.50,0:18:15.02,Chinese,,0,0,0,,当你向左移动时,你不需要管填充什么数字,只需要管位移
Dialogue: 0,0:18:15.62,0:18:21.34,English,,0,0,0,,I'm shifting by three,so I'll take the low order five bits move them over three positions
Dialogue: 0,0:18:15.62,0:18:21.34,Chinese,,0,0,0,,当我左移 3 位时,我会把低位的 5 个比特向左移动 3 位
Dialogue: 0,0:18:21.68,0:18:23.30,English,,0,0,0,,Then fill in with a zero
Dialogue: 0,0:18:21.68,0:18:23.30,Chinese,,0,0,0,,然后在低位填零
Dialogue: 0,0:18:23.64,0:18:31.55,English,,0,0,0,,And whatever was in the upper positions of that original words they just sort of disappear into nowhere
Dialogue: 0,0:18:23.64,0:18:31.55,Chinese,,0,0,0,,而原始数据中的高位都会消失无踪
Dialogue: 0,0:18:32.10,0:18:39.56,English,,0,0,0,,Similarly if I do a right shift I take the upper six bits I move them over to positions and I fill in with zeros
Dialogue: 0,0:18:32.10,0:18:39.56,Chinese,,0,0,0,,同样,如果我做右移,我将把高位移动相应的位置,然后用零填充
Dialogue: 0,0:18:40.32,0:18:44.96,English,,0,0,0,,So that's a logical shift and that's well it's logic
Dialogue: 0,0:18:40.32,0:18:44.96,Chinese,,0,0,0,,所以这是一个逻辑右移,这就是逻辑
Dialogue: 0,0:18:45.44,0:18:48.00,English,,0,0,0,,There's another flavor called the arithmetic shift
Dialogue: 0,0:18:45.44,0:18:48.00,Chinese,,0,0,0,,还有另外一种叫算术右移
Dialogue: 0,0:18:48.00,0:18:54.38,English,,0,0,0,,Which it differs in that the rule for what bits you fill in with are not based on the are
Dialogue: 0,0:18:48.00,0:18:54.38,Chinese,,0,0,0,,它的不同之处在于填充的规则不是固定的
Dialogue: 0,0:18:55.70,0:19:01.56,English,,0,0,0,,not zeros necessarily but it's whatever the most significant bit was in the original value
Dialogue: 0,0:18:55.70,0:19:01.56,Chinese,,0,0,0,,不一定是零,但它是原始值中的符号位
Dialogue: 0,0:19:02.00,0:19:04.90,English,,0,0,0,,So it doesn't matter here because the most significant bit was zero
Dialogue: 0,0:19:02.00,0:19:04.90,Chinese,,0,0,0,,所以这里没关系,因为符号位是零
Dialogue: 0,0:19:04.90,0:19:11.74,English,,0,0,0,, But you'll see in the case here of where the leading bit was a 1
Dialogue: 0,0:19:04.90,0:19:11.74,Chinese,,0,0,0,,但在这里你看到首位是 1
Dialogue: 0,0:19:12.80,0:19:18.68,English,,0,0,0,, That when I shift it to the right arithmetic we I'll fill it in with 1
Dialogue: 0,0:19:12.80,0:19:18.68,Chinese,,0,0,0,,当我进行右移时,我将用 1 填充它
Dialogue: 0,0:19:19.40,0:19:25.38,English,,0,0,0,,And that'll make sense more when we understand how negative numbers get represented in a machine
Dialogue: 0,0:19:19.40,0:19:25.38,Chinese,,0,0,0,,当我们理解负数在机器中的表示形式就能明白其中的含义
Dialogue: 0,0:19:25.98,0:19:28.82,English,,0,0,0,,And that's the purpose of it and why it's called arithmetic
Dialogue: 0,0:19:25.98,0:19:28.82,Chinese,,0,0,0,,以及这样设计的目的,和为什么它被称为算术右移
Dialogue: 0,0:19:31.60,0:19:37.54,English,,0,0,0,,Um the other thing is confusing to people is
Dialogue: 0,0:19:31.60,0:19:37.54,Chinese,,0,0,0,,另一件事让人感到困惑
Dialogue: 0,0:19:37.80,0:19:44.80,English,,0,0,0,,What should happen if you say I want to shift an 8-bit number 8 positions to the left
Dialogue: 0,0:19:37.80,0:19:44.80,Chinese,,0,0,0,,如果你说我想将一个 8 位数的 8 位移到左边,应该发生什么
Dialogue: 0,0:19:54.60,0:19:58.92,English,,0,0,0,,And X is a single byte what do you think you should get
Dialogue: 0,0:19:54.60,0:19:58.92,Chinese,,0,0,0,,而 x 是一个单字节,你认为你应该得到什么?
Dialogue: 0,0:20:02.84,0:20:07.86,English,,0,0,0,, Zero that would be a pretty logical thing you kind of shift all those bits out you fill them with zeros
Dialogue: 0,0:20:02.84,0:20:07.86,Chinese,,0,0,0,,零这将是一个非常合乎逻辑的事情,你把所有这些位移出来,你用零填充它们
Dialogue: 0,0:20:08.40,0:20:13.12,English,,0,0,0,,On most machines you'll get whatever x was
Dialogue: 0,0:20:08.40,0:20:13.12,Chinese,,0,0,0,,在大多数机器上你会得到 0
Dialogue: 0,0:20:17.38,0:20:21.88,English,,0,0,0,,Because what will do is it will compute this number mod 8
Dialogue: 0,0:20:17.38,0:20:21.88,Chinese,,0,0,0,,因为它将要做计算是将这个数字模 8
Dialogue: 0,0:20:25.90,0:20:28.64,English,,0,0,0,,And the reason that happens is if you think about it
Dialogue: 0,0:20:25.90,0:20:28.64,Chinese,,0,0,0,,你们考虑一下发生这种情况的原因
Dialogue: 0,0:20:28.64,0:20:34.02,English,,0,0,0,,It's looking at just the lower two three bits of the shift amount and ignoring all the rest
Dialogue: 0,0:20:28.64,0:20:34.02,Chinese,,0,0,0,,只要观察低位的 3 个比特位移,忽略所有其他位
Dialogue: 0,0:20:34.26,0:20:36.90,English,,0,0,0,, So that's effectively like module 8
Dialogue: 0,0:20:34.26,0:20:36.90,Chinese,,0,0,0,,所以这就像模 8 一样
Dialogue: 0,0:20:37.76,0:20:41.38,English,,0,0,0,,So that's just a warning and some machines it does
Dialogue: 0,0:20:37.76,0:20:41.38,Chinese,,0,0,0,,一些机器只是会给出警告提示
Dialogue: 0,0:20:41.38,0:20:44.44,English,,0,0,0,,What you just thought it should and other machines it does this
Dialogue: 0,0:20:41.38,0:20:44.44,Chinese,,0,0,0,,你只是认为它应该和其他机器这样做
Dialogue: 0,0:20:44.88,0:20:50.12,English,,0,0,0,,And so there's no no guarantee and in C that it will be one way or the other
Dialogue: 0,0:20:44.88,0:20:50.12,Chinese,,0,0,0,,因此在 C 语言当中不能保证只有一种方式
Dialogue: 0,0:20:52.80,0:20:58.70,English,,0,0,0,,Same with if you try to shift left by a negative number that might be logically
Dialogue: 0,0:20:52.80,0:20:58.70,Chinese,,0,0,0,,同样如果你尝试向左移动负数可能结果是逻辑右移
Dialogue: 0,0:20:58.70,0:21:02.88,English,,0,0,0,,Well I guess you really want to shift right then but that usually doesn't work either
Dialogue: 0,0:20:58.70,0:21:02.88,Chinese,,0,0,0,,那么我想你其实想要右移,但通常也不起作用
Dialogue: 0,0:21:05.40,0:21:09.06,English,,0,0,0,,So now let's talk about number representations
Dialogue: 0,0:21:05.40,0:21:09.06,Chinese,,0,0,0,,现在让我们来谈谈数字表示
Dialogue: 0,0:21:09.68,0:21:10.32,English,,0,0,0,,And
Dialogue: 0,0:21:09.68,0:21:10.32,Chinese,,0,0,0,,和
Dialogue: 0,0:21:12.10,0:21:18.24,English,,0,0,0,,This is sort of a very core its idea that you have to really have wired in you
Dialogue: 0,0:21:12.10,0:21:18.24,Chinese,,0,0,0,,这是它的一个非常核心的想法,你必须用心理解他
Dialogue: 0,0:21:18.56,0:21:22.20,English,,0,0,0,,And I'm going to illustrate it with some examples
Dialogue: 0,0:21:18.56,0:21:22.20,Chinese,,0,0,0,,我将用一些例子来说明它
Dialogue: 0,0:21:27.74,0:21:35.30,English,,0,0,0,,So the these two equations that are everything that we'll talk about sort of stems from them
Dialogue: 0,0:21:27.74,0:21:35.30,Chinese,,0,0,0,,所以这两个方程就是我们要谈论的一切,都源于他们
Dialogue: 0,0:21:35.98,0:21:38.64,English,,0,0,0,,So one is if you have an unsigned number
Dialogue: 0,0:21:35.98,0:21:38.64,Chinese,,0,0,0,,所以一个是如果你有一个无符号的数字
Dialogue: 0,0:21:39.22,0:21:45.18,English,,0,0,0,,Then basically...it keeps jumping on me
Dialogue: 0,0:21:39.22,0:21:45.18,Chinese,,0,0,0,,然后基本上...(它不断打扰我)
Dialogue: 0,0:21:46.78,0:21:52.42,English,,0,0,0,,If you have an unsigned number then this is just the conversion
Dialogue: 0,0:21:46.78,0:21:52.42,Chinese,,0,0,0,,如果你有一个无符号的数字,那么这只是转换
Dialogue: 0,0:21:52.42,0:22:00.56,English,,0,0,0,,B2U means from a bit level representation to an unsigned number of some bit pattern
Dialogue: 0,0:21:52.42,0:22:00.56,Chinese,,0,0,0,,B2U 的意思是从比特位模式转化成无符号数的编码表示
Dialogue: 0,0:22:00.56,0:22:04.68,English,,0,0,0,,It just says we'll just add up the sum of the weighted bits
Dialogue: 0,0:22:00.56,0:22:04.68,Chinese,,0,0,0,,它意思是我们将加权位求和(看屏幕左上角那个公式)
Dialogue: 0,0:22:04.94,0:22:07.86,English,,0,0,0,,Where each bit is weighted by a power of two
Dialogue: 0,0:22:04.94,0:22:07.86,Chinese,,0,0,0,,每个比特用 2 的幂来加权
Dialogue: 0,0:22:08.48,0:22:10.88,English,,0,0,0,, And the only difference when we look at two's complement
Dialogue: 0,0:22:08.48,0:22:10.88,Chinese,,0,0,0,,当我们看补码的时候和无符号数唯一的区别就是
Dialogue: 0,0:22:10.88,0:22:14.74,English,,0,0,0,,Which is a way to represent both negative and positive numbers
Dialogue: 0,0:22:10.88,0:22:14.74,Chinese,,0,0,0,,这种方法可以表示负数和正数
Dialogue: 0,0:22:15.00,0:22:18.86,English,,0,0,0,,It's we'll consider the most significant bit to be what's called the sign bit
Dialogue: 0,0:22:15.00,0:22:18.86,Chinese,,0,0,0,,这里我们认为最重要的一点是所谓的符号位
Dialogue: 0,0:22:19.60,0:22:21.66,English,,0,0,0,,So it will have a negative value
Dialogue: 0,0:22:19.60,0:22:21.66,Chinese,,0,0,0,,所以它会有一个负值
Dialogue: 0,0:22:22.10,0:22:26.68,English,,0,0,0,,So let me just illustrate this with I'll use some running examples
Dialogue: 0,0:22:22.10,0:22:26.68,Chinese,,0,0,0,,所以让我来说明一下,我将使用一些运行示例
Dialogue: 0,0:22:26.68,0:22:34.90,English,,0,0,0,,We'll just use five bit numbers just as a way it really helps often if you're trying to understand this stuff to do it for some smaller cases
Dialogue: 0,0:22:26.68,0:22:34.90,Chinese,,0,0,0,,我们只会使用五位数字,使用较小的位数通常可以帮助你们理解补码
Dialogue: 0,0:22:36.10,0:22:39.38,English,,0,0,0,,So if we think about bit positions
Dialogue: 0,0:22:36.10,0:22:39.38,Chinese,,0,0,0,,所以如果我们考虑比特的位置
Dialogue: 0,0:22:49.38,0:22:51.28,English,,0,0,0,,zero through four
Dialogue: 0,0:22:49.38,0:22:51.28,Chinese,,0,0,0,,从0到4
Dialogue: 0,0:22:59.18,0:23:04.70,English,,0,0,0,,Then those represent of different powers of two weights of as I've shown
Dialogue: 0,0:22:59.18,0:23:04.70,Chinese,,0,0,0,,我写的这些数字表示 2 的不同幂的值
Dialogue: 0,0:23:05.40,0:23:08.04,English,,0,0,0,,And so now if we take some bit a pattern
Dialogue: 0,0:23:05.40,0:23:08.04,Chinese,,0,0,0,,如果我们采取位模式
Dialogue: 0,0:23:18.92,0:23:19.96,English,,0,0,0,,Like so
Dialogue: 0,0:23:18.92,0:23:19.96,Chinese,,0,0,0,,像这样
Dialogue: 0,0:23:20.34,0:23:21.56,English,,0,0,0,,So that's what I'll call X
Dialogue: 0,0:23:20.34,0:23:21.58,Chinese,,0,0,0,,我把它叫做 X
Dialogue: 0,0:23:23.84,0:23:26.30,English,,0,0,0,,and if I want to convert that to an unsigned number
Dialogue: 0,0:23:23.84,0:23:26.30,Chinese,,0,0,0,,如果我要将其转换为无符号数
Dialogue: 0,0:23:26.98,0:23:37.32,English,,0,0,0,,I will just combine 8+4+1 and I'll get 13
Dialogue: 0,0:23:26.98,0:23:37.32,Chinese,,0,0,0,,我只需要 8+4+1,我会得到 13
Dialogue: 0,0:23:38.18,0:23:38.76,English,,0,0,0,,all right
Dialogue: 0,0:23:38.18,0:23:38.76,Chinese,,0,0,0,,好吧
Dialogue: 0,0:23:39.20,0:23:48.97,English,,0,0,0,,So that's all that equation says the left hand equations just take the the bit positions that are ones use the corresponding power of 2 and you're done
Dialogue: 0,0:23:39.20,0:23:48.97,Chinese,,0,0,0,,所以这个方程式展示的等式左边只是将对应比特位的 2 的幂累加,就能得到结果
Dialogue: 0,0:23:50.18,0:23:53.56,English,,0,0,0,,And similarly if I have a number where there's a leading bit
Dialogue: 0,0:23:50.18,0:23:53.56,Chinese,,0,0,0,,同样的,如果我有一个数字,最高位是 1
Dialogue: 0,0:24:01.48,0:24:09.06,English,,0,0,0,,It will be 16+4+2 so that will be 22
Dialogue: 0,0:24:01.48,0:24:09.06,Chinese,,0,0,0,,它将是 16+4+2,因此将是22
Dialogue: 0,0:24:11.20,0:24:13.26,English,,0,0,0,,And so that's the unsigned case
Dialogue: 0,0:24:11.20,0:24:13.26,Chinese,,0,0,0,,这是无符号的情况
Dialogue: 0,0:24:15.24,0:24:18.32,English,,0,0,0,,And the sign case is the same idea
Dialogue: 0,0:24:15.24,0:24:18.32,Chinese,,0,0,0,,有符号数情况是一样的想法
Dialogue: 0,0:24:18.86,0:24:26.02,English,,0,0,0,,Except that most significant bit has a negative value
Dialogue: 0,0:24:18.86,0:24:26.02,Chinese,,0,0,0,,除了最高位是负值
Dialogue: 0,0:24:27.08,0:24:29.42,English,,0,0,0,,So it will still this is i
Dialogue: 0,0:24:27.08,0:24:29.42,Chinese,,0,0,0,,所以它仍然是 i
Dialogue: 0,0:24:32.70,0:24:36.50,English,,0,0,0,,And our weights will be 1,2,4,8
Dialogue: 0,0:24:32.70,0:24:36.50,Chinese,,0,0,0,,我们的权重将是 1,2,4,8
Dialogue: 0,0:24:36.54,0:24:38.40,English,,0,0,0,,But this will be -16
Dialogue: 0,0:24:36.54,0:24:38.40,Chinese,,0,0,0,,但是这将是 -16
Dialogue: 0,0:24:39.54,0:24:43.76,English,,0,0,0,,So that's what the equation on the right is saying this fit
Dialogue: 0,0:24:39.54,0:24:43.76,Chinese,,0,0,0,,所以这就是右边的这个公式所说的
Dialogue: 0,0:24:44.80,0:24:47.68,English,,0,0,0,,Now we're going to change it from being a negative number to a positive
Dialogue: 0,0:24:44.80,0:24:47.68,Chinese,,0,0,0,,现在我们要把它从一个负数变成一个正数
Dialogue: 0,0:24:48.42,0:24:52.32,English,,0,0,0,,So obviously if I have this is my bit pattern it's going to be the same because
Dialogue: 0,0:24:48.42,0:24:52.32,Chinese,,0,0,0,,所以很显然,如果我有这是我的位模式,它将是相同的,因为
Dialogue: 0,0:24:52.78,0:25:01.16,English,,0,0,0,,The other bits stayed at the same so let's do it for this case of 10110
Dialogue: 0,0:24:52.78,0:25:01.16,Chinese,,0,0,0,,其他位保持不变,所以让我们来做这个 10110 的情况
Dialogue: 0,0:25:03.12,0:25:10.04,English,,0,0,0,,So that will be -16+4+2=-10
Dialogue: 0,0:25:03.12,0:25:10.04,Chinese,,0,0,0,,所以这将是 -16+4+2=-10
Dialogue: 0,0:25:13.92,0:25:17.78,English,,0,0,0,,So you see in this case we have the same bit pattern
Dialogue: 0,0:25:13.92,0:25:17.78,Chinese,,0,0,0,,所以你在这种情况下看到我们有相同的位模式
Dialogue: 0,0:25:18.86,0:25:24.32,English,,0,0,0,, It's just if we interpret it you know how we think about what number this represents
Dialogue: 0,0:25:18.86,0:25:24.32,Chinese,,0,0,0,,只是如果我们解释它,你就知道我们如何看待这个代表的数字
Dialogue: 0,0:25:24.64,0:25:30.92,English,,0,0,0,,Then in one case it's a positive number 22 in another case it's a negative number -10
Dialogue: 0,0:25:24.64,0:25:30.92,Chinese,,0,0,0,,那么在另一种情况下,这是一个正数 22,在另一种情况下,它是一个负数 -10
Dialogue: 0,0:25:32.50,0:25:34.80,English,,0,0,0,, And that's what these equations you see
Dialogue: 0,0:25:32.50,0:25:34.80,Chinese,,0,0,0,,这就是你看到的这些方程
Dialogue: 0,0:25:40.16,0:25:45.04,English,,0,0,0,,And so the most significant bit is sometimes called the sign bit because
Dialogue: 0,0:25:40.16,0:25:45.04,Chinese,,0,0,0,,因此,最高位有时称为符号位
Dialogue: 0,0:25:45.04,0:25:47.46,English,,0,0,0,,If it's a 1 the number is going to be negative
Dialogue: 0,0:25:45.04,0:25:47.46,Chinese,,0,0,0,,如果它是 1,则该数字将是负数
Dialogue: 0,0:25:51.22,0:25:55.72,English,,0,0,0,, So let's sort of think about
Dialogue: 0,0:25:51.22,0:25:55.72,Chinese,,0,0,0,,所以让我们思考一下
Dialogue: 0,0:25:57.94,0:26:01.40,English,,0,0,0,,What extreme,what are the sort of extreme ranges of numbers
Dialogue: 0,0:25:57.94,0:26:01.40,Chinese,,0,0,0,,可以表示的数在那个区间的极值是多少
Dialogue: 0,0:26:01.40,0:26:03.62,English,,0,0,0,,We can get with these two different representations
Dialogue: 0,0:26:01.40,0:26:03.62,Chinese,,0,0,0,,在这两种不同数的表示方式下我们得到不同的区间
Dialogue: 0,0:26:12.48,0:26:16.24,English,,0,0,0,, So obviously if these are all zeros my number is going to equal zero
Dialogue: 0,0:26:12.48,0:26:16.24,Chinese,,0,0,0,,所以显然,如果这些都是零,我能得到 0
Dialogue: 0,0:26:20.00,0:26:34.42,English,,0,0,0,,And if it's all 1 it will be 16+8+4+2+1 will be 31
Dialogue: 0,0:26:20.00,0:26:34.42,Chinese,,0,0,0,,如果全是 1,那么将是 16+8+4+2+1 将是 31
Dialogue: 0,0:26:35.86,0:26:39.62,English,,0,0,0,,And over here for the two's complement
Dialogue: 0,0:26:35.86,0:26:39.62,Chinese,,0,0,0,,在这里展示一下补码的情况
Dialogue: 0,0:26:41.68,0:26:51.82,English,,0,0,0,,The smallest number,well the largest number will actually be let me do it this way
Dialogue: 0,0:26:41.68,0:26:51.82,Chinese,,0,0,0,,最小的数字,最大的数字会是,让我这样做
Dialogue: 0,0:26:52.02,0:26:56.74,English,,0,0,0,,Actually the most negative number so the smallest number and the strictest sense of the word is
Dialogue: 0,0:26:52.02,0:26:56.74,Chinese,,0,0,0,,其实严格的讲最小的负数是最小的数字
Dialogue: 0,0:26:57.56,0:27:03.20,English,,0,0,0,, is this it's -16. you can argue this by the way
Dialogue: 0,0:26:57.56,0:27:03.20,Chinese,,0,0,0,,这是 -16,你可以使用这种方式来论证
Dialogue: 0,0:27:03.48,0:27:08.54,English,,0,0,0,,This is the only bit that has a negative weight all the other ones have positive ones
Dialogue: 0,0:27:03.48,0:27:08.54,Chinese,,0,0,0,,这是唯一一个负数权重的比特位,所有其他都是正数
Dialogue: 0,0:27:08.54,0:27:13.16,English,,0,0,0,,So certainly one and all the rest being zeros is going to be the smallest number
Dialogue: 0,0:27:08.54,0:27:13.16,Chinese,,0,0,0,,所以第一位是 1 其余所有位都是 0 就是最小的数字
Dialogue: 0,0:27:13.60,0:27:16.26,English,,0,0,0,,And similarly the largest number you can represent
Dialogue: 0,0:27:13.60,0:27:16.26,Chinese,,0,0,0,,同样,你可以得到最大的数
Dialogue: 0,0:27:20.44,0:27:27.32,English,,0,0,0,,We'll be 8+4+2+1 which is 15
Dialogue: 0,0:27:20.44,0:27:27.32,Chinese,,0,0,0,,8+4+2+1 这是 15
Dialogue: 0,0:27:31.42,0:27:33.80,English,,0,0,0,, And so we call this number UMax
Dialogue: 0,0:27:31.42,0:27:33.80,Chinese,,0,0,0,,我们把这个数字称为 UMax
Dialogue: 0,0:27:38.52,0:27:41.06,English,,0,0,0,,And we call this number TMax
Dialogue: 0,0:27:38.52,0:27:41.06,Chinese,,0,0,0,,我们称这个数为 TMax
Dialogue: 0,0:27:43.72,0:27:45.54,English,,0,0,0,,And we call this number TMin
Dialogue: 0,0:27:43.72,0:27:45.54,Chinese,,0,0,0,,我们把这个数叫做 TMin
Dialogue: 0,0:27:48.58,0:27:51.36,English,,0,0,0,,So there's a few things to observe about these numbers
Dialogue: 0,0:27:48.58,0:27:51.36,Chinese,,0,0,0,,这几个数有几点需要注意的
Dialogue: 0,0:27:55.04,0:27:58.42,English,,0,0,0,,That remember this is a 5-bit word size right so
Dialogue: 0,0:27:55.04,0:27:58.42,Chinese,,0,0,0,,请记住,这是字长位 5 的情况
Dialogue: 0,0:28:00.62,0:28:06.23,English,,0,0,0,,You'll see that 31 is pretty close to 32 right
Dialogue: 0,0:28:00.62,0:28:06.23,Chinese,,0,0,0,,你看到 31 很接近 32
Dialogue: 0,0:28:06.23,0:28:10.82,English,,0,0,0,,In fact it's 2^5-1
Dialogue: 0,0:28:06.23,0:28:10.82,Chinese,,0,0,0,,实际上它是 2^5-1
Dialogue: 0,0:28:12.56,0:28:17.04,English,,0,0,0,,And in general if it's a five and that's for a 5-bit word size
Dialogue: 0,0:28:12.56,0:28:17.04,Chinese,,0,0,0,,一般来说,如果字长是 5
Dialogue: 0,0:28:17.04,0:28:27.14,English,,0,0,0,,So you would say in general it will have value 2^w if I have a W bit number minus 1 and that's what this shows
Dialogue: 0,0:28:17.04,0:28:27.14,Chinese,,0,0,0,,一般来讲如果你有 w 位数,你能的到的值就是 2^w-1,就像这个呈现的一样
Dialogue: 0,0:28:31.04,0:28:36.96,English,,0,0,0,,And similarly over here this is -2^4
Dialogue: 0,0:28:31.04,0:28:36.96,Chinese,,0,0,0,,同样,这是 -2^4
Dialogue: 0,0:28:40.38,0:28:46.74,English,,0,0,0,,And so we'd say in general that will be -2^w if it's a W bit number minus 1
Dialogue: 0,0:28:40.38,0:28:46.74,Chinese,,0,0,0,,一般来说我们有 w 位数,一般会说,我们能到的值是 -2^(w-1)
Dialogue: 0,0:28:49.22,0:28:54.18,English,,0,0,0,,Right all these make sense by the way you'll notice one other feature is
Dialogue: 0,0:28:49.22,0:28:54.18,Chinese,,0,0,0,,所有这些都是有道理的,你会注意到另一个特征是
Dialogue: 0,0:28:58.60,0:29:06.74,English,,0,0,0,, A whole string of ones like this if you sum up those digits 8 + 4 + 2 + 1
Dialogue: 0,0:28:58.60,0:29:06.74,Chinese,,0,0,0,,像这样一整串数字都是由 1 组成,如果你把它们每位表示的值相加
Dialogue: 0,0:29:07.12,0:29:11.84,English,,0,0,0,, Will be 1 less than the next bit position up
Dialogue: 0,0:29:07.12,0:29:11.84,Chinese,,0,0,0,,得到的值将比前一位表示的值少 1
Dialogue: 0,0:29:13.22,0:29:18.64,English,,0,0,0,,And you can think about that if you were to count this number
Dialogue: 0,0:29:13.22,0:29:18.64,Chinese,,0,0,0,,你可以考虑计算一下这个数字
Dialogue: 0,0:29:18.94,0:29:25.16,English,,0,0,0,,If you were to increment this number by 1 you'd get 1 1 is 0 carry 1 and so forth
Dialogue: 0,0:29:18.94,0:29:25.16,Chinese,,0,0,0,,如果你将这个数字加 1,你会看到 1 加 1 得 0 进 1,一次类推
Dialogue: 0,0:29:25.22,0:29:29.42,English,,0,0,0,,And you'd carry that value up to this position so these various ways you can think about that
Dialogue: 0,0:29:25.22,0:29:29.42,Chinese,,0,0,0,,你得到的值就是这个位置表示的数,所以你可以用这些不同的方式来思考
Dialogue: 0,0:29:31.52,0:29:37.38,English,,0,0,0,,And then similarly this number is 2^4-1
Dialogue: 0,0:29:31.52,0:29:37.38,Chinese,,0,0,0,,同样这个数字是 2^4-1
Dialogue: 0,0:29:38.52,0:29:42.98,English,,0,0,0,,And so that's equal to 2^(w-1) - 1
Dialogue: 0,0:29:38.52,0:29:42.98,Chinese,,0,0,0,,等于 2^(w-1)-1
Dialogue: 0,0:29:47.76,0:29:49.40,English,,0,0,0,,As is shown here
Dialogue: 0,0:29:47.76,0:29:49.40,Chinese,,0,0,0,,如这里所示
Dialogue: 0,0:29:51.98,0:29:59.02,English,,0,0,0,, So there's a lot of the book goes through formulas and does derivation
Dialogue: 0,0:29:51.98,0:29:59.02,Chinese,,0,0,0,,很多课本都是通过公式来推导
Dialogue: 0,0:29:59.60,0:30:03.68,English,,0,0,0,, But if you just think about it in these smaller scale ways
Dialogue: 0,0:29:59.60,0:30:03.68,Chinese,,0,0,0,,但是,如果你只是用很小规模的来思考它
Dialogue: 0,0:30:04.10,0:30:10.10,English,,0,0,0,, The intuition is pretty easy to get and don't get lost in in formulas when
Dialogue: 0,0:30:04.10,0:30:10.10,Chinese,,0,0,0,,就能很直观的感受到这种规律,并且在公式中不会迷失方向
Dialogue: 0,0:30:10.26,0:30:13.92,English,,0,0,0,,Really at the gut level it's a fairly straightforward sort of ideas
Dialogue: 0,0:30:10.26,0:30:13.92,Chinese,,0,0,0,,在内心深处,这是一个相当直接的想法
Dialogue: 0,0:30:15.00,0:30:18.52,English,,0,0,0,, Or if you ever see some confusions and you're confused
Dialogue: 0,0:30:15.00,0:30:18.52,Chinese,,0,0,0,,或者如果你看到一些混乱,你感到困惑
Dialogue: 0,0:30:19.12,0:30:22.25,English,,0,0,0,, Try out some small examples and see what they're saying
Dialogue: 0,0:30:19.12,0:30:22.25,Chinese,,0,0,0,,尝试一些小例子,看看他们在说什么
Dialogue: 0,0:30:22.90,0:30:31.60,English,,0,0,0,,Another interesting number in the world of two's complement is what happens when you have all ones in your bit patterns
Dialogue: 0,0:30:22.90,0:30:31.60,Chinese,,0,0,0,,二进制补码世界中还有另一个有趣的数字,就是当所有的位都是 1 时候会发生什么
Dialogue: 0,0:30:35.80,0:30:45.66,English,,0,0,0,,And that will have mate -16+8+4+2+1 and that will equal -1
Dialogue: 0,0:30:35.80,0:30:45.66,Chinese,,0,0,0,,这将得到 -16+8+4+2+1,等于 -1
Dialogue: 0,0:30:48.00,0:30:53.85,English,,0,0,0,,So the bit pattern all ones is always a -1 in this representation
Dialogue: 0,0:30:48.00,0:30:53.85,Chinese,,0,0,0,,所以在这种表示中,所有的位都是 1 的结果是 -1
Dialogue: 0,0:30:54.04,0:30:59.74,English,,0,0,0,,I should mention two's complement is not the only way to represent a positive and negative numbers
Dialogue: 0,0:30:54.04,0:30:59.74,Chinese,,0,0,0,,我应该提到过补码并不是表示正数和负数的唯一方式
Dialogue: 0,0:30:59.74,0:31:01.48,English,,0,0,0,,what's sometimes called signed numbers
Dialogue: 0,0:30:59.74,0:31:01.48,Chinese,,0,0,0,,有时称为有符号数字
Dialogue: 0,0:31:01.78,0:31:06.62,English,,0,0,0,,But it's so universal that you'll hardly ever encounter another case
Dialogue: 0,0:31:01.78,0:31:06.62,Chinese,,0,0,0,,但它很普遍,你几乎不会遇到另一种情况
Dialogue: 0,0:31:07.12,0:31:14.62,English,,0,0,0,, So if you understand two's complement you have a pretty good understanding of what really is going on
Dialogue: 0,0:31:07.12,0:31:14.62,Chinese,,0,0,0,,所以,如果你理解了补码,你就能很好地理解真正发生了什么
Dialogue: 0,0:31:22.06,0:31:26.90,English,,0,0,0,,So these numbers I call UMax the biggest unsigned number
Dialogue: 0,0:31:22.06,0:31:26.90,Chinese,,0,0,0,,这些数字中 UMax 最大的无符号数字
Dialogue: 0,0:31:27.38,0:31:32.60,English,,0,0,0,,TMin the smallest most negative two's complement monitor and
Dialogue: 0,0:31:27.38,0:31:32.60,Chinese,,0,0,0,,TMin 是补码的最小值
Dialogue: 0,0:31:32.60,0:31:36.42,English,,0,0,0,,TMax the largest most positive two's complement
Dialogue: 0,0:31:32.60,0:31:36.42,Chinese,,0,0,0,,TMax 是补码的最大值
Dialogue: 0,0:31:36.76,0:31:42.46,English,,0,0,0,,This chart shows the range of values for different word sizes different numbers of bytes
Dialogue: 0,0:31:36.76,0:31:42.46,Chinese,,0,0,0,,此图表显示了不同字长数值的范围
Dialogue: 0,0:31:43.02,0:31:51.16,English,,0,0,0,,And so you'll see that with an 8 bit number you only have 256 possibilities right
Dialogue: 0,0:31:43.02,0:31:51.16,Chinese,,0,0,0,,所以你会看到, 8 位只有 256 个可能
Dialogue: 0,0:31:54.66,0:32:01.68,English,,0,0,0,, And so we can either choose to rate think of those as representing the range from 0 to 255
Dialogue: 0,0:31:54.66,0:32:01.68,Chinese,,0,0,0,,因此,我们可以选择将其视为表示的范围是从 0 到 255
Dialogue: 0,0:32:01.86,0:32:07.52,English,,0,0,0,, Or basically with two's complement numbers we're just doing a sort of a wraparound we're saying
Dialogue: 0,0:32:01.86,0:32:07.52,Chinese,,0,0,0,,或者基本上用二进制补码来表示,我们只是在做一个简单的说明
Dialogue: 0,0:32:07.52,0:32:13.24,English,,0,0,0,,Well we're going to have half of them be negative and the other half will be either 0 or positive
Dialogue: 0,0:32:07.52,0:32:13.24,Chinese,,0,0,0,,那么我们将有一半是负数,另一半是 0 或正数
Dialogue: 0,0:32:16.62,0:32:19.34,English,,0,0,0,,And so it's a pretty limited range of values of course
Dialogue: 0,0:32:16.62,0:32:19.34,Chinese,,0,0,0,,所以这当然是一个相当有限的值范围
Dialogue: 0,0:32:19.34,0:32:25.74,English,,0,0,0,,Then 16 and believe me back when computers had 16-bit word sizes
Dialogue: 0,0:32:19.34,0:32:25.74,Chinese,,0,0,0,,然后 16,当计算机有 16 位字长时,请相信我
Dialogue: 0,0:32:25.74,0:32:29.48,English,,0,0,0,, It was a nuisance to keep your numbers within that range
Dialogue: 0,0:32:25.74,0:32:29.48,Chinese,,0,0,0,,将数字保持在该范围内是一件令人讨厌的事情
Dialogue: 0,0:32:29.94,0:32:33.61,English,,0,0,0,, And 32 gives you a pretty decent range it used to be said
Dialogue: 0,0:32:29.94,0:32:33.61,Chinese,,0,0,0,,而 32 给你一个相当不错的范围,曾经有人说过
Dialogue: 0,0:32:33.98,0:32:41.00,English,,0,0,0,,Microsoft had to go to 64-bit word size to represent Bill Gates's net worth but
Dialogue: 0,0:32:33.98,0:32:41.00,Chinese,,0,0,0,,微软必须以 64 位字大小来表示比尔盖茨的净资产,但是
Dialogue: 0,0:32:43.90,0:32:49.66,English,,0,0,0,,For me at least this would easily handle my range of normal day-to-day transactions so
Dialogue: 0,0:32:43.90,0:32:49.66,Chinese,,0,0,0,,至少对我来说,这很容易处理我正常的日常交易范围
Dialogue: 0,0:32:51.74,0:33:00.16,English,,0,0,0,, But now with 64 bits at least to us nowadays those seem like really big numbers and hard to imagine exceeding the bounds of those
Dialogue: 0,0:32:51.74,0:33:00.16,Chinese,,0,0,0,,但现在至少对我们来说,64 位数字看起来非常庞大,很难想象它们超出了这些限制
Dialogue: 0,0:33:04.88,0:33:11.68,English,,0,0,0,, So one interesting feature that you noticed here was I was um
Dialogue: 0,0:33:04.88,0:33:11.68,Chinese,,0,0,0,,所以你注意到的一个有趣的功能就是
Dialogue: 0,0:33:15.82,0:33:17.96,English,,0,0,0,,like this case here
Dialogue: 0,0:33:15.82,0:33:17.96,Chinese,,0,0,0,,像这里的情况一样
Dialogue: 0,0:33:24.88,0:33:27.02,English,,0,0,0,,In this case here...
Dialogue: 0,0:33:24.88,0:33:27.02,Chinese,,0,0,0,,在这里这里...
Dialogue: 0,0:33:36.16,0:33:39.88,English,,0,0,0,,And then this case here of all ones
Dialogue: 0,0:33:36.16,0:33:39.88,Chinese,,0,0,0,,然后在这里所有的情况
Dialogue: 0,0:33:43.28,0:33:47.98,English,,0,0,0,,I was comparing it to this case here of all ones
Dialogue: 0,0:33:43.28,0:33:47.98,Chinese,,0,0,0,,我在这里比较所有的这种情况
Dialogue: 0,0:33:49.40,0:33:54.24,English,,0,0,0,,So in other words in both these cases and it's a little hard to jump boards here
Dialogue: 0,0:33:49.40,0:33:54.24,Chinese,,0,0,0,,换句话说,在这两种情况下,(这个黑板不好抬...)
Dialogue: 0,0:33:56.64,0:34:00.04,English,,0,0,0,,You're seeing that you have the same bit pattern in either case
Dialogue: 0,0:33:56.64,0:34:00.04,Chinese,,0,0,0,,无论哪种情况,你都会看到相同的位模式
Dialogue: 0,0:34:01.12,0:34:06.56,English,,0,0,0,,But they the numeric they represent different numeric values because one is a two's complement case
Dialogue: 0,0:34:01.12,0:34:06.56,Chinese,,0,0,0,,但他们的数字代表不同的数值,因为一个是补码
Dialogue: 0,0:34:07.80,0:34:10.06,English,,0,0,0,,And the other is an unsigned right
Dialogue: 0,0:34:07.80,0:34:10.06,Chinese,,0,0,0,,另一个是无符号数
Dialogue: 0,0:34:10.12,0:34:14.38,English,,0,0,0,,And you can actually see the relation between them is pretty simple
Dialogue: 0,0:34:10.12,0:34:14.38,Chinese,,0,0,0,,你可以看到它们之间的关系非常简单
Dialogue: 0,0:34:14.76,0:34:24.08,English,,0,0,0,, Because basically what we're doing is we're jumping between +16 and -16 between those
Dialogue: 0,0:34:14.76,0:34:24.08,Chinese,,0,0,0,,因为基本上我们正在做的是我们在这些之间的 +16 和 -16 之间变化
Dialogue: 0,0:34:24.44,0:34:27.84,English,,0,0,0,,And so you'd expect it to change by 32 right
Dialogue: 0,0:34:24.44,0:34:27.84,Chinese,,0,0,0,,所以你会期望它改变为 32
Dialogue: 0,0:34:28.54,0:34:32.16,English,,0,0,0,,And you see that here that this is 31 here and -1
Dialogue: 0,0:34:28.54,0:34:32.16,Chinese,,0,0,0,,你在这里看到,这里是 31 和 -1
Dialogue: 0,0:34:32.68,0:34:43.14,English,,0,0,0,,This is 22 and -10 so they're differ from each other by plus -32 ,2^4, two to the word size
Dialogue: 0,0:34:32.68,0:34:43.14,Chinese,,0,0,0,,这是 22 和 -10,所以他们是不同的,加上 -32,2^4
Dialogue: 0,0:34:43.60,0:34:48.80,English,,0,0,0,,and so we there's sort of a long derivation in the book and things here
Dialogue: 0,0:34:43.60,0:34:48.80,Chinese,,0,0,0,,所以我们在这本书和这里的东西中有很长一段时间的推导
Dialogue: 0,0:34:48.80,0:34:53.60,English,,0,0,0,,But that connection is actually fairly important
Dialogue: 0,0:34:48.80,0:34:53.60,Chinese,,0,0,0,,但是这种联系实际上相当重要
Dialogue: 0,0:34:54.06,0:35:01.82,English,,0,0,0,,Because when you jump back and forth between unsigned numbers and two's complement numbers in C
Dialogue: 0,0:34:54.06,0:35:01.82,Chinese,,0,0,0,,因为当你在 C 中的无符号数和补码之间跳来跳去
Dialogue: 0,0:35:03.08,0:35:07.44,English,,0,0,0,,That's the jump that you get in other words
Dialogue: 0,0:35:03.08,0:35:07.44,Chinese,,0,0,0,,这就是跳跃或者你可以用其他词
Dialogue: 0,0:35:07.64,0:35:10.48,English,,0,0,0,,when of and so
Dialogue: 0,0:35:07.64,0:35:10.48,Chinese,,0,0,0,,何时等等
Dialogue: 0,0:35:12.50,0:35:18.12,English,,0,0,0,,You'll often find cases where what used to be a very large number
Dialogue: 0,0:35:12.50,0:35:18.12,Chinese,,0,0,0,,你经常会发现一种情况那就是一个非常大的数字
Dialogue: 0,0:35:18.12,0:35:20.80,English,,0,0,0,,Because it was unsigned all of a sudden becomes a negative number
Dialogue: 0,0:35:18.12,0:35:20.80,Chinese,,0,0,0,,因为它是无符号数,突然变成了一个负数
Dialogue: 0,0:35:20.80,0:35:22.72,English,,0,0,0,,Because it's considered two's complement
Dialogue: 0,0:35:20.80,0:35:22.72,Chinese,,0,0,0,,因为它被认为是补码
Dialogue: 0,0:35:24.00,0:35:26.96,English,,0,0,0,,So that's what this next part covers will say that
Dialogue: 0,0:35:24.00,0:35:26.96,Chinese,,0,0,0,,所以接下来的部分就是这么说的
Dialogue: 0,0:35:32.24,0:35:35.91,English,,0,0,0,,If we take a cart of 4 bit numbers and
Dialogue: 0,0:35:32.24,0:35:35.91,Chinese,,0,0,0,,如果我们使用一个 4 位的数值模式
Dialogue: 0,0:35:36.14,0:35:43.36,English,,0,0,0,,We write out all the possible values is unsigned or as two's complement numbers
Dialogue: 0,0:35:36.14,0:35:43.36,Chinese,,0,0,0,,我们写出所有可能的值都是无符号或二进制补码
Dialogue: 0,0:35:43.64,0:35:48.83,English,,0,0,0,,Then the ones where the low the higher bit is 0 will be the same in both cases
Dialogue: 0,0:35:43.64,0:35:48.83,Chinese,,0,0,0,,那么在最高位是 0 的情况下,两种表示方式的值是相同的
Dialogue: 0,0:35:49.38,0:35:54.80,English,,0,0,0,,The ones where the higher order bit is a 1 in this case will differ by 16 2^4
Dialogue: 0,0:35:49.38,0:35:54.80,Chinese,,0,0,0,,在这种情况下,最高位是 1,它们将相差 16, 2^4
Dialogue: 0,0:35:56.70,0:36:02.88,English,,0,0,0,,And similarly you'll notice that these numbers there's a unique
Dialogue: 0,0:35:56.70,0:36:02.88,Chinese,,0,0,0,,同样你会注意到这些数字是唯一的
Dialogue: 0,0:36:03.16,0:36:07.56,English,,0,0,0,,It goes unique in both directions there's a for any given bit pattern
Dialogue: 0,0:36:03.16,0:36:07.56,Chinese,,0,0,0,,它在两个方向都是独一无二的,适用于任何给定的位模式
Dialogue: 0,0:36:07.78,0:36:10.95,English,,0,0,0,,There's a unique number it represents and
Dialogue: 0,0:36:07.78,0:36:10.95,Chinese,,0,0,0,,有一个独特的数字代表
Dialogue: 0,0:36:11.32,0:36:16.36,English,,0,0,0,,And similarly for any number within the given range there's a unique bit pattern
Dialogue: 0,0:36:11.32,0:36:16.36,Chinese,,0,0,0,,同样,对于给定范围内的任何数字,都有一个唯一的位模式
Dialogue: 0,0:36:17.02,0:36:22.68,English,,0,0,0,,So we can sort of jump between those two and say
Dialogue: 0,0:36:17.02,0:36:22.68,Chinese,,0,0,0,,所以我们可以在这两者之间跳跃并说
Dialogue: 0,0:36:23.88,0:36:32.18,English,,0,0,0,, I can make up a rule for converting between a two's complement number X and an unsigned number UX
Dialogue: 0,0:36:23.88,0:36:32.18,Chinese,,0,0,0,,我可以定义一个在补码 X 和一个无符号数字 UX 之间转换的规则
Dialogue: 0,0:36:32.36,0:36:37.50,English,,0,0,0,,That basically says I'll use the same bits I'll just think of them as being different numbers
Dialogue: 0,0:36:32.36,0:36:37.50,Chinese,,0,0,0,,基本上说,我会使用相同的位,我只是认为它们是不同的数字
Dialogue: 0,0:36:38.10,0:36:42.12,English,,0,0,0,, And so and you can go either way
Dialogue: 0,0:36:38.10,0:36:42.12,Chinese,,0,0,0,,所以你可以去任何一个方式
Dialogue: 0,0:36:42.42,0:36:55.40,English,,0,0,0,, So for example if we thought of this is a a two's complement representative representation, it's -1
Dialogue: 0,0:36:42.42,0:36:55.40,Chinese,,0,0,0,,举例来说,如果我们认为这是补码表示,这是数是 -1
Dialogue: 0,0:36:56.06,0:37:04.48,English,,0,0,0,,This function I'm calling T2U goes from that number -1 to this number 31
Dialogue: 0,0:36:56.06,0:37:04.48,Chinese,,0,0,0,,我调用 T2U 的这个函数,就能将 -1 这个数转成 31
Dialogue: 0,0:37:06.12,0:37:11.90,English,,0,0,0,,Where in between the two I'm saying they both have the same bit pattern
Dialogue: 0,0:37:06.12,0:37:11.90,Chinese,,0,0,0,,在两者之间我说他们都有相同的位模式
Dialogue: 0,0:37:16.88,0:37:23.42,English,,0,0,0,,And the reason why this rather function that would otherwise seem to have no particular use is important
Dialogue: 0,0:37:16.88,0:37:23.42,Chinese,,0,0,0,,而这个功能似乎没有特别用处的原因很重要
Dialogue: 0,0:37:23.50,0:37:30.66,English,,0,0,0,,Because that's basically what happens in C or actually in the program
Dialogue: 0,0:37:23.50,0:37:30.66,Chinese,,0,0,0,,因为这基本上是 C 语言或实际在程序中发生的事情
Dialogue: 0,0:37:30.94,0:37:35.52,English,,0,0,0,,On the computer itself has no clue whether a given bit pattern if it's something
Dialogue: 0,0:37:30.94,0:37:35.52,Chinese,,0,0,0,,在计算机上本身并不知道是否给定位模式
Dialogue: 0,0:37:35.52,0:37:41.80,English,,0,0,0,, You're thinking of as being a negative number or two's complement number it's just a bunch of bits to it
Dialogue: 0,0:37:35.52,0:37:41.80,Chinese,,0,0,0,,你正在考虑作为一个负数或二进制补码,它只是一堆比特
Dialogue: 0,0:37:43.60,0:37:51.22,English,,0,0,0,,And similarly so we can go back and forth between a two's complement and unsigned keeping the bit patterns the same
Dialogue: 0,0:37:43.60,0:37:51.22,Chinese,,0,0,0,,同样,我们可以在补码和无符号二进制之间来回保持位模式相同
Dialogue: 0,0:37:54.72,0:38:01.32,English,,0,0,0,,And so I'll call that T2U when I go from signed to unsigned two's complement unsigned
Dialogue: 0,0:37:54.72,0:38:01.32,Chinese,,0,0,0,,所以当我从 signed 到 unsigned 二进制补码无符号时,我会调用该 T2U
Dialogue: 0,0:38:01.60,0:38:04.94,English,,0,0,0,, And say well I'll call U2T if I go from unsigned to signed
Dialogue: 0,0:38:01.60,0:38:04.94,Chinese,,0,0,0,,如果我从 unsigned 到 signed 我会调用 U2T
Dialogue: 0,0:38:07.36,0:38:13.44,English,,0,0,0,,And as I mentioned the difference for the the numbers where the high-order bit is a 1
Dialogue: 0,0:38:07.36,0:38:13.44,Chinese,,0,0,0,,正如我提到的最高位是 1 的数字的区别
Dialogue: 0,0:38:13.68,0:38:18.28,English,,0,0,0,,will be by a factor 2^w where w is the word size of the word
Dialogue: 0,0:38:13.68,0:38:18.28,Chinese,,0,0,0,,乘以一个因子 2^w,其中 w 是字长
Dialogue: 0,0:38:22.16,0:38:24.66,English,,0,0,0,, And so this can be thought of as a function
Dialogue: 0,0:38:22.16,0:38:24.66,Chinese,,0,0,0,,所以这可以被看做是一个函数
Dialogue: 0,0:38:27.28,0:38:28.48,English,,0,0,0,, Where
Dialogue: 0,0:38:27.28,0:38:28.48,Chinese,,0,0,0,,哪里
Dialogue: 0,0:38:34.84,0:38:36.18,English,,0,0,0,,Let me just draw it up
Dialogue: 0,0:38:34.84,0:38:36.18,Chinese,,0,0,0,,让我把它画出来
Dialogue: 0,0:38:47.48,0:38:51.98,English,,0,0,0,,Over here with my five of bit numbers
Dialogue: 0,0:38:47.48,0:38:51.98,Chinese,,0,0,0,,在这里用我的五位数字
Dialogue: 0,0:38:55.30,0:39:01.50,English,,0,0,0,,That is the number this is two's complement again so that was the number -16
Dialogue: 0,0:38:55.30,0:39:01.50,Chinese,,0,0,0,,这是补码,所以这是数字 -16
Dialogue: 0,0:39:02.72,0:39:06.18,English,,0,0,0,,And then there'll be some other negative numbers up to all ones
Dialogue: 0,0:39:02.72,0:39:06.18,Chinese,,0,0,0,,然后这是另一个补码都是1的负数
Dialogue: 0,0:39:09.48,0:39:11.00,English,,0,0,0,,This is number negative one
Dialogue: 0,0:39:09.48,0:39:11.00,Chinese,,0,0,0,,这是数字是负数
Dialogue: 0,0:39:11.60,0:39:18.78,English,,0,0,0,,Then I'll have zero and so forth and then all up to
Dialogue: 0,0:39:11.60,0:39:18.78,Chinese,,0,0,0,,然后我会有零等等,然后一切
Dialogue: 0,0:39:23.26,0:39:29.06,English,,0,0,0,,+15
Dialogue: 0,0:39:23.26,0:39:29.06,Chinese,,0,0,0,,+15
Dialogue: 0,0:39:30.82,0:39:32.96,English,,0,0,0,,Destroys,I got myself in trouble
Dialogue: 0,0:39:30.82,0:39:32.96,Chinese,,0,0,0,,我陷入了麻烦
Dialogue: 0,0:39:37.00,0:39:41.34,English,,0,0,0,,Blackboard management is they didn't teach me this in school
Dialogue: 0,0:39:37.00,0:39:41.34,Chinese,,0,0,0,,黑板管理们没有在学校教我这个
Dialogue: 0,0:39:44.42,0:39:50.18,English,,0,0,0,, So I'm gonna use two boards and ones here
Dialogue: 0,0:39:44.42,0:39:50.18,Chinese,,0,0,0,,所以我要在这里使用两块黑板
Dialogue: 0,0:40:02.29,0:40:15.58,English,,0,0,0,,Okay let me send this out,okay we'll make it work
Dialogue: 0,0:40:02.29,0:40:15.58,Chinese,,0,0,0,,好,让我推上去,好了我们继续
Dialogue: 0,0:40:16.52,0:40:21.84,English,,0,0,0,,So now when we go from the T2U function then
Dialogue: 0,0:40:16.52,0:40:21.84,Chinese,,0,0,0,,所以现在我们从 T2U 函数开始
Dialogue: 0,0:40:22.64,0:40:25.10,English,,0,0,0,,These numbers are going to just carry over
Dialogue: 0,0:40:22.64,0:40:25.10,Chinese,,0,0,0,,这些数字将继续存在
Dialogue: 0,0:40:25.50,0:40:30.18,English,,0,0,0,, We'll get 0 up through 15
Dialogue: 0,0:40:25.50,0:40:30.18,Chinese,,0,0,0,,我们会从 0 到 15
Dialogue: 0,0:40:32.46,0:40:36.84,English,,0,0,0,, But now this number here will become positive 16
Dialogue: 0,0:40:32.46,0:40:36.84,Chinese,,0,0,0,,但现在这个数字会变成正数 16
Dialogue: 0,0:40:41.70,0:40:51.02,English,,0,0,0,,And all ones will become positive 31 right
Dialogue: 0,0:40:41.70,0:40:51.02,Chinese,,0,0,0,,所有的位都是 1 会得到 +31
Dialogue: 0,0:40:51.34,0:40:56.46,English,,0,0,0,,And so that's what this picture is showing is it for the pink numbers
Dialogue: 0,0:40:51.34,0:40:56.46,Chinese,,0,0,0,,所以这张照片显示的是粉色数字
Dialogue: 0,0:40:57.50,0:41:03.25,English,,0,0,0,,are the ones that flip between negative and actually the largest of the positive numbers
Dialogue: 0,0:40:57.50,0:41:03.25,Chinese,,0,0,0,,是那些在负数和实际上最大的正数之间翻转的数字
Dialogue: 0,0:41:03.92,0:41:08.68,English,,0,0,0,,And then the green numbers are the ones that stay the same because they're leading bits or zeros
Dialogue: 0,0:41:03.92,0:41:08.68,Chinese,,0,0,0,,然后绿色数字保持不变,因为它们的最高位是 0
Dialogue: 0,0:41:14.82,0:41:16.26,English,,0,0,0,, So why does this matter bits or zeros
Dialogue: 0,0:41:14.82,0:41:16.26,Chinese,,0,0,0,,那么为什么这有点重要
Dialogue: 0,0:41:16.56,0:41:24.36,English,,0,0,0,,You never thought if you programmed in Python or even Java, you don't see that
Dialogue: 0,0:41:16.56,0:41:24.36,Chinese,,0,0,0,,如果你用 Python 或甚至 Java 编程,你就不会考虑这些
Dialogue: 0,0:41:24.66,0:41:33.32,English,,0,0,0,,And the reason is because C is one of the few languages where unsigned is actually an explicit datatype
Dialogue: 0,0:41:24.66,0:41:33.32,Chinese,,0,0,0,,原因是因为 C 是少数 unsigned 是一个明确的数据类型的语言之一
Dialogue: 0,0:41:34.32,0:41:37.94,English,,0,0,0,,So you can declare a value being unsigned
Dialogue: 0,0:41:34.32,0:41:37.94,Chinese,,0,0,0,,所以你可以声明一个 unsigned 的值
Dialogue: 0,0:41:38.34,0:41:42.52,English,,0,0,0,,And it's you can if you just say unsigned what you're really saying is unsigned int
Dialogue: 0,0:41:38.34,0:41:42.52,Chinese,,0,0,0,,如果你只是说 unsigned 你真正的意思是 unsigned int
Dialogue: 0,0:41:43.32,0:41:48.46,English,,0,0,0,,Or you can call something an unsigned care and unsigned short or an unsigned long
Dialogue: 0,0:41:43.32,0:41:48.46,Chinese,,0,0,0,,或者你可以调用一些 unsigned short 或 unsigned long
Dialogue: 0,0:41:49.78,0:41:56.68,English,,0,0,0,,So and you're declaring and see that it should think about using this representation we show on the right
Dialogue: 0,0:41:49.78,0:41:56.68,Chinese,,0,0,0,,所以你在使用时应该考虑使用我们在右边展示的这个表示
Dialogue: 0,0:41:56.98,0:41:59.72,English,,0,0,0,,When it's working on those numbers
Dialogue: 0,0:41:56.98,0:41:59.72,Chinese,,0,0,0,,当它在处理这些数字时
Dialogue: 0,0:42:01.82,0:42:08.28,English,,0,0,0,,So that's sort of one thing and this it's one thing if you declare a number and use it that way
Dialogue: 0,0:42:01.82,0:42:08.28,Chinese,,0,0,0,,如果你声明了一个数字并以这种方式使用它
Dialogue: 0,0:42:08.28,0:42:17.30,English,,0,0,0,,But what gets people and the often got you is if you declare something if you have a in this case
Dialogue: 0,0:42:08.28,0:42:17.30,Chinese,,0,0,0,,但是,如果你在这种情况下声明某种东西,那么我们得到的是什么
Dialogue: 0,0:42:17.72,0:42:21.34,English,,0,0,0,,Something that's declared as a two's complement number X to TX
Dialogue: 0,0:42:17.72,0:42:21.34,Chinese,,0,0,0,,一些声明为 X 的补码数 TX
Dialogue: 0,0:42:22.00,0:42:26.34,English,,0,0,0,,And you assign it a value you at Y X it'll do an implicit casting
Dialogue: 0,0:42:22.00,0:42:26.34,Chinese,,0,0,0,,你给 Y X 赋值,它会进行隐式转换
Dialogue: 0,0:42:26.84,0:42:32.18,English,,0,0,0,, Which is exactly based on this conversion that we've been talking about and vice versa
Dialogue: 0,0:42:26.84,0:42:32.18,Chinese,,0,0,0,,这正是基于我们一直在谈论的这种转换,反之亦然
Dialogue: 0,0:42:34.32,0:42:41.86,English,,0,0,0,, And so as this example goes through this goes through some examples that
Dialogue: 0,0:42:34.32,0:42:41.86,Chinese,,0,0,0,,所以这个例子告诉我们
Dialogue: 0,0:42:42.24,0:42:49.06,English,,0,0,0,,If I look at two numbers and I compare them or I actually I do any operation on them
Dialogue: 0,0:42:42.24,0:42:49.06,Chinese,,0,0,0,,如果我看看两个数字,然后比较它们,或者实际上我会对它们进行一些操作
Dialogue: 0,0:42:49.06,0:42:56.18,English,,0,0,0,, I add them divide them anything implicitly it will try to make these to be of the same type
Dialogue: 0,0:42:49.06,0:42:56.18,Chinese,,0,0,0,,我将它们求和、或分开,其中隐式的尝试使它们成为相同的类型
Dialogue: 0,0:42:56.72,0:43:00.68,English,,0,0,0,,And the way it will do that is to say if both of them are signed
Dialogue: 0,0:42:56.72,0:43:00.68,Chinese,,0,0,0,,而这样做的方式就是说如果两个数都是有符号数
Dialogue: 0,0:43:01.00,0:43:05.34,English,,0,0,0,, Then I'll do I'll treat them as a signed case
Dialogue: 0,0:43:01.00,0:43:05.34,Chinese,,0,0,0,,那么我会做我会把他们作为一个 signed 的情况
Dialogue: 0,0:43:05.60,0:43:07.88,English,,0,0,0,,If either of them is unsigned
Dialogue: 0,0:43:05.60,0:43:07.88,Chinese,,0,0,0,,如果其中任何一个无符号
Dialogue: 0,0:43:08.24,0:43:12.78,English,,0,0,0,,Then I'll convert the other one to be an unsigned number and do the operation
Dialogue: 0,0:43:08.24,0:43:12.78,Chinese,,0,0,0,,然后我会将另一个转换为一个无符号数并进行操作
Dialogue: 0,0:43:13.20,0:43:16.86,English,,0,0,0,, And so in particular this set of examples is imagine
Dialogue: 0,0:43:13.20,0:43:16.86,Chinese,,0,0,0,,特别是通过这个例子可想而知
Dialogue: 0,0:43:16.86,0:43:21.73,English,,0,0,0,, I'm comparing these I'm saying these numbers are either equal less or greater
Dialogue: 0,0:43:16.86,0:43:21.73,Chinese,,0,0,0,,我比较这些我说这些数字要么等于要么小于要么大于
Dialogue: 0,0:43:22.14,0:43:27.66,English,,0,0,0,,What will the outcomes be and the key to answering that question is to first of all figure out
Dialogue: 0,0:43:22.14,0:43:27.66,Chinese,,0,0,0,,结果会是什么,回答这个问题的关键首先要弄清楚
Dialogue: 0,0:43:28.20,0:43:32.52,English,,0,0,0,, Okay is it a signed or an unsigned comparison should I convert
Dialogue: 0,0:43:28.20,0:43:32.52,Chinese,,0,0,0,,好的,这是否是一个有符号或无符号的比较,我是否需要转换
Dialogue: 0,0:43:33.40,0:43:39.80,English,,0,0,0,, One of these numbers to either of these numbers to an unsigned form before I do it
Dialogue: 0,0:43:33.40,0:43:39.80,Chinese,,0,0,0,,这些数字之一,这些数字之前,我这样做了一个无符号的形式
Dialogue: 0,0:43:40.38,0:43:44.38,English,,0,0,0,,And the rule was if either argument is unsigned then you got to do it
Dialogue: 0,0:43:40.38,0:43:44.38,Chinese,,0,0,0,,而规则是如果任何一个无符号数,那么你必须这样做
Dialogue: 0,0:43:45.30,0:43:53.80,English,,0,0,0,,And as you see when you put a u at the end either a u or U at the end of a numeric constant
Dialogue: 0,0:43:45.30,0:43:53.80,Chinese,,0,0,0,,正如你所看到的,当你在结尾处放置一个 u 或 U 时
Dialogue: 0,0:43:54.20,0:43:56.70,English,,0,0,0,,You're saying this is an unsigned value
Dialogue: 0,0:43:54.20,0:43:56.70,Chinese,,0,0,0,,这就是一个无符号值
Dialogue: 0,0:43:57.50,0:44:05.32,English,,0,0,0,, So for example if we compare a zero and zero unsigned they're equal
Dialogue: 0,0:43:57.50,0:44:05.32,Chinese,,0,0,0,,举例来说,如果我们比较零和无符号零,它们是相等的
Dialogue: 0,0:44:07.50,0:44:13.12,English,,0,0,0,,And if we combine negative one compare negative one to zero
Dialogue: 0,0:44:07.50,0:44:13.12,Chinese,,0,0,0,,如果我们比较 -1 和 0
Dialogue: 0,0:44:13.72,0:44:17.20,English,,0,0,0,,We'll get that the first one is less
Dialogue: 0,0:44:13.72,0:44:17.20,Chinese,,0,0,0,,我们会得到第一个小于
Dialogue: 0,0:44:17.46,0:44:19.74,English,,0,0,0,,Because -1 is less than 0
Dialogue: 0,0:44:17.46,0:44:19.74,Chinese,,0,0,0,,因为 -1 小于 0
Dialogue: 0,0:44:20.40,0:44:25.22,English,,0,0,0,, But what would happen with the next one when we compare negative 1 to an unsigned 0
Dialogue: 0,0:44:20.40,0:44:25.22,Chinese,,0,0,0,,但是当我们将 -1 与无符号 0 进行比较时,会发生什么
Dialogue: 0,0:44:26.86,0:44:30.24,English,,0,0,0,,greater right
Dialogue: 0,0:44:26.86,0:44:30.24,Chinese,,0,0,0,,更大,对吧
Dialogue: 0,0:44:31.10,0:44:40.54,English,,0,0,0,,So this is the surprise and it has to do with...a number that I erased
Dialogue: 0,0:44:31.10,0:44:40.54,Chinese,,0,0,0,,所以这是一个惊喜,它与我擦掉的一个数字有关
Dialogue: 0,0:44:44.38,0:44:47.64,English,,0,0,0,,But we can still get it remember this is negative one
Dialogue: 0,0:44:44.38,0:44:47.64,Chinese,,0,0,0,,但我们仍然可以记住这是 -1
Dialogue: 0,0:44:49.84,0:44:54.20,English,,0,0,0,, But when I cast that to an unsigned number
Dialogue: 0,0:44:49.84,0:44:54.20,Chinese,,0,0,0,,但是当我把它转换成一个无符号数时
Dialogue: 0,0:44:54.71,0:45:03.84,English,,0,0,0,, I'm flipping this from -16 to +16 and turning this into 31 I'm turning it into actually the largest number I can represent
Dialogue: 0,0:44:54.71,0:45:03.84,Chinese,,0,0,0,,我把这个从 -16 改为 +16,并把它变成 31,我把它变成了我能代表的最大数字
Dialogue: 0,0:45:04.64,0:45:06.72,English,,0,0,0,,And so it will be greater than zero
Dialogue: 0,0:45:04.64,0:45:06.72,Chinese,,0,0,0,,所以它会大于零
Dialogue: 0,0:45:07.80,0:45:15.42,English,,0,0,0,, So it's a little bit weird to think about I took an u0 which after all is to 0 and compared it to a negative 1
Dialogue: 0,0:45:07.80,0:45:15.42,Chinese,,0,0,0,,所以有点奇怪的是,来让我们想想一个 u0 与 -1 进行比较
Dialogue: 0,0:45:15.70,0:45:21.38,English,,0,0,0,,And it said oh you really meant 31 didn't you or whatever word size we're using
Dialogue: 0,0:45:15.70,0:45:21.38,Chinese,,0,0,0,,它说哦,你真的意味着 31 或我们正在使用的任何字长
Dialogue: 0,0:45:21.86,0:45:23.32,English,,0,0,0,, And so it said it's greater
Dialogue: 0,0:45:21.86,0:45:23.32,Chinese,,0,0,0,,所以它说这更大
Dialogue: 0,0:45:25.14,0:45:29.04,English,,0,0,0,,And basically the rest of these you can answer in a similar way
Dialogue: 0,0:45:25.14,0:45:29.04,Chinese,,0,0,0,,基本上其余的问题你可以用类似的方式回答
Dialogue: 0,0:45:32.76,0:45:39.02,English,,0,0,0,, That these two numbers are this is clearly one smaller than this
Dialogue: 0,0:45:32.76,0:45:39.02,Chinese,,0,0,0,,这两个数字是这个数字显然小于这个数字
Dialogue: 0,0:45:40.28,0:45:46.04,English,,0,0,0,,No I'm sorry this is a positive this is a negative number and
Dialogue: 0,0:45:40.28,0:45:46.04,Chinese,,0,0,0,,不,我很抱歉,这是正的,这是一个负数
Dialogue: 0,0:45:46.18,0:45:51.14,English,,0,0,0,,I compare those and the positive will be greater than the negative
Dialogue: 0,0:45:46.18,0:45:51.14,Chinese,,0,0,0,,我比较这些正数的将大于负数
Dialogue: 0,0:45:51.86,0:45:55.68,English,,0,0,0,, I'll tell you in a minute why this number is written this way
Dialogue: 0,0:45:51.86,0:45:55.68,Chinese,,0,0,0,,我会在一分钟内告诉你为什么这个数字是这样写的
Dialogue: 0,0:45:56.82,0:45:59.78,English,,0,0,0,, The next one it's the same pair of numbers
Dialogue: 0,0:45:56.82,0:45:59.78,Chinese,,0,0,0,,下一个它是同一对数字
Dialogue: 0,0:46:01.30,0:46:02.54,English,,0,0,0,,But you see it's flipped
Dialogue: 0,0:46:01.30,0:46:02.54,Chinese,,0,0,0,,但你看它翻转了
Dialogue: 0,0:46:03.80,0:46:13.68,English,,0,0,0,,And the reason is this number on the left is TMax for
Dialogue: 0,0:46:03.80,0:46:13.68,Chinese,,0,0,0,,原因是这个左边的数字是 TMax 的
Dialogue: 0,0:46:19.82,0:46:22.82,English,,0,0,0,,So it's the bit pattern in a 32-bit number
Dialogue: 0,0:46:19.82,0:46:22.82,Chinese,,0,0,0,,所以这是 32 位数字中的位模式
Dialogue: 0,0:46:50.92,0:46:53.46,English,,0,0,0,,And to this day I have not memorized this number by the way
Dialogue: 0,0:46:50.92,0:46:53.46,Chinese,,0,0,0,,直到今天,我还没有记住这个数字
Dialogue: 0,0:46:53.88,0:46:57.44,English,,0,0,0,,But and then this number is actually TMin
Dialogue: 0,0:46:53.88,0:46:57.44,Chinese,,0,0,0,,但是,这个数字实际上是 TMin
Dialogue: 0,0:47:15.68,0:47:24.72,English,,0,0,0,,And that when I subtract you can think of it as this is negative TMax - 1 so that's TMin
Dialogue: 0,0:47:15.68,0:47:24.72,Chinese,,0,0,0,, 当我减去时你可以认为它是负的 TMax-1,这就是 TMin
Dialogue: 0,0:47:25.14,0:47:29.30,English,,0,0,0,, So if I do an unsigned comparison between those two now think of those
Dialogue: 0,0:47:25.14,0:47:29.30,Chinese,,0,0,0,,所以,如果我现在想一下这两者之间的无符号比较
Dialogue: 0,0:47:29.58,0:47:36.72,English,,0,0,0,,This leading bit not being a negative weight but a positive weight you'll see that this is a bigger number than this one
Dialogue: 0,0:47:29.58,0:47:36.72,Chinese,,0,0,0,,这个首位不是一个负权重,但一个正权重,你会看到这是一个比这个更大的数字
Dialogue: 0,0:47:41.96,0:47:48.42,English,,0,0,0,, And so it goes that -1 is greater than -2 if they're unsigned
Dialogue: 0,0:47:41.96,0:47:48.42,Chinese,,0,0,0,,因此,如果它们是无符号的,则 -1 大于 -2
Dialogue: 0,0:47:49.40,0:47:56.71,English,,0,0,0,, Because -1 is you can think of it as converts into UMax it'll be the biggest number possible
Dialogue: 0,0:47:49.40,0:47:56.71,Chinese,,0,0,0,,因为 -1 可以把它看作转换成 UMax,它可能是最大的数字
Dialogue: 0,0:47:57.06,0:48:05.84,English,,0,0,0,,And -2 will be would be 11110
Dialogue: 0,0:47:57.06,0:48:05.84,Chinese,,0,0,0,,-2 将会是 11110
Dialogue: 0,0:48:17.98,0:48:20.44,English,,0,0,0,,So that can get fairly confusing
Dialogue: 0,0:48:17.98,0:48:20.44,Chinese,,0,0,0,,所以这可能会让人相当困惑
Dialogue: 0,0:48:23.78,0:48:29.98,English,,0,0,0,,One final quirk this way of writing this number is there's a little side in the book about it
Dialogue: 0,0:48:23.78,0:48:29.98,Chinese,,0,0,0,,这种数字的最后一个奇怪的地方,书中有一点提到它的一面
Dialogue: 0,0:48:30.54,0:48:37.84,English,,0,0,0,, If you write a business number Oh as you'd expect - as - blah blah blah 648
Dialogue: 0,0:48:30.54,0:48:37.84,Chinese,,0,0,0,,如果你写一个商业编号哦,比如你想要 - 吧啦吧啦 648
Dialogue: 0,0:48:40.60,0:48:47.70,English,,0,0,0,,It will actually get the C compiler gets kind of confused by that for obscure reasons
Dialogue: 0,0:48:40.60,0:48:47.70,Chinese,,0,0,0,,它实际上会让 C 编译器因为一些模糊的原因而感到困惑
Dialogue: 0,0:48:48.14,0:48:54.36,English,,0,0,0,, One other thing I should point out that it's a property that I don't think we cover well enough here
Dialogue: 0,0:48:48.14,0:48:54.36,Chinese,,0,0,0,,还有一件事我应该指出,这是一个性质,我认为我们在这里讲的得不够全面
Dialogue: 0,0:48:56.44,0:48:57.88,English,,0,0,0,,Let me see
Dialogue: 0,0:48:56.44,0:48:57.88,Chinese,,0,0,0,,让我看看
Dialogue: 0,0:49:02.64,0:49:06.50,English,,0,0,0,,There's a few things that the tides don't really cover here and I don't know why not
Dialogue: 0,0:49:02.64,0:49:06.50,Chinese,,0,0,0,,现在的趋势是不讲这个方面,我不知道为什么不
Dialogue: 0,0:49:07.26,0:49:08.58,English,,0,0,0,,They like to point out
Dialogue: 0,0:49:07.26,0:49:08.58,Chinese,,0,0,0,,他们喜欢指出
Dialogue: 0,0:49:13.66,0:49:17.62,English,,0,0,0,,That are kind of useful properties to keep track of
Dialogue: 0,0:49:13.66,0:49:17.62,Chinese,,0,0,0,,这是一些有用的特性可以跟踪
Dialogue: 0,0:49:25.38,0:49:32.84,English,,0,0,0,,It's that you notice that if you look at the absolute value of TMax
Dialogue: 0,0:49:25.38,0:49:32.84,Chinese,,0,0,0,,这是你注意到,如果你看看 TMax 的绝对值
Dialogue: 0,0:49:35.26,0:49:38.12,English,,0,0,0,,And you compare it to the absolute value of TMin
Dialogue: 0,0:49:35.26,0:49:38.12,Chinese,,0,0,0,,你将它与 TMin 的绝对值进行比较
Dialogue: 0,0:49:40.72,0:49:46.90,English,,0,0,0,,That it's off by one right
Dialogue: 0,0:49:40.72,0:49:46.90,Chinese,,0,0,0,,它们相差 1,对吧
Dialogue: 0,0:49:47.36,0:49:50.24,English,,0,0,0,,So that the negative number is more negative
Dialogue: 0,0:49:47.36,0:49:50.24,Chinese,,0,0,0,,所以负数更小
Dialogue: 0,0:49:50.24,0:49:55.42,English,,0,0,0,,The smallest negative number is more negative than the largest positive number is positive
Dialogue: 0,0:49:50.24,0:49:55.42,Chinese,,0,0,0,,最小的负数比最大的正数更负
Dialogue: 0,0:49:56.24,0:49:59.44,English,,0,0,0,,And the reason for that actually is fairly simple if you think about
Dialogue: 0,0:49:56.24,0:49:59.44,Chinese,,0,0,0,,如果你想一想,其中的原因其实很简单
Dialogue: 0,0:49:59.78,0:50:05.62,English,,0,0,0,, It is that the cases where you have zeros
Dialogue: 0,0:49:59.78,0:50:05.62,Chinese,,0,0,0,,这是你有零的情况
Dialogue: 0,0:50:07.88,0:50:09.36,English,,0,0,0,,Include the number 0
Dialogue: 0,0:50:07.88,0:50:09.36,Chinese,,0,0,0,,包含数字 0
Dialogue: 0,0:50:21.24,0:50:22.56,English,,0,0,0,,So you can see it better
Dialogue: 0,0:50:21.24,0:50:22.56,Chinese,,0,0,0,,(这样你们能看的更清楚)
Dialogue: 0,0:50:26.40,0:50:32.40,English,,0,0,0,,And there's two to the half of range is occupied by those numbers
Dialogue: 0,0:50:26.40,0:50:32.40,Chinese,,0,0,0,,取值范围的一半被负数占据
Dialogue: 0,0:50:32.96,0:50:36.86,English,,0,0,0,, And the negative numbers are all negative
Dialogue: 0,0:50:32.96,0:50:36.86,Chinese,,0,0,0,,负数范围内都是负数
Dialogue: 0,0:50:42.10,0:50:46.80,English,,0,0,0,,And there's so the other half of the range is in there
Dialogue: 0,0:50:42.10,0:50:46.80,Chinese,,0,0,0,,另外还有一半是在那里
Dialogue: 0,0:50:48.26,0:50:51.70,English,,0,0,0,,And the point is that you had to use one of these four zero
Dialogue: 0,0:50:48.26,0:50:51.70,Chinese,,0,0,0,,关键是你必须使用这四个零中的一个
Dialogue: 0,0:50:52.16,0:50:57.34,English,,0,0,0,,And so they're only there's one left one less value left over
Dialogue: 0,0:50:52.16,0:50:57.34,Chinese,,0,0,0,,所以他们只剩下一个值
Dialogue: 0,0:50:57.72,0:51:01.82,English,,0,0,0,, And that's why you end up with this through a symmetry
Dialogue: 0,0:50:57.72,0:51:01.82,Chinese,,0,0,0,,这就是为什么你可以通过对称性结束这一点
Dialogue: 0,0:51:02.50,0:51:06.92,English,,0,0,0,,And this a symmetry is the cause of no end of pain in various ways
Dialogue: 0,0:51:02.50,0:51:06.92,Chinese,,0,0,0,,而这种对称性是以各种方式解决错误的原因
Dialogue: 0,0:51:07.72,0:51:15.62,English,,0,0,0,,That like a few the classic example is if you implement absolute value
Dialogue: 0,0:51:07.72,0:51:15.62,Chinese,,0,0,0,,这就像一些经典的例子,如果你实现绝对值
Dialogue: 0,0:51:33.40,0:51:39.96,English,,0,0,0,,Like so what do you what does this return for TMin
Dialogue: 0,0:51:33.40,0:51:39.96,Chinese,,0,0,0,,像这样,你们觉得输入 TMin 的返回值是什么?
Dialogue: 0,0:51:44.62,0:51:50.32,English,,0,0,0,,Yeah the returns TMin in we'll talk a little bit basically
Dialogue: 0,0:51:44.62,0:51:50.32,Chinese,,0,0,0,,是的,我们的返回的也是 TMin,基本上会谈一点
Dialogue: 0,0:51:51.84,0:51:56.04,English,,0,0,0,, When you try to negate this number that's here
Dialogue: 0,0:51:51.84,0:51:56.04,Chinese,,0,0,0,,当你试图减去这里的这个数字
Dialogue: 0,0:51:59.14,0:52:00.84,English,,0,0,0,, You'll end up with it back again
Dialogue: 0,0:51:59.14,0:52:00.84,Chinese,,0,0,0,,你最终会的得到这个数
Dialogue: 0,0:52:08.06,0:52:12.92,English,,0,0,0,,So it's always a corner case and whenever we do program testing
Dialogue: 0,0:52:08.06,0:52:12.92,Chinese,,0,0,0,,所以,当我们进行程序测试时,它总是一个角落案例
Dialogue: 0,0:52:12.92,0:52:16.24,English,,0,0,0,, We always throw that case in there to break things question
Dialogue: 0,0:52:12.92,0:52:16.24,Chinese,,0,0,0,,我们总是把那个例子扔在那里来解决问题
Dialogue: 0,0:52:17.00,0:52:33.36,English,,0,0,0,, well that case you said oh yeah big number but how negative - one yes
Dialogue: 0,0:52:17.00,0:52:33.36,Chinese,,0,0,0,,那么你说,哦,是大数字,但如何变成一个负数 - 是的
Dialogue: 0,0:52:33.36,0:52:40.00,English,,0,0,0,,No that's what they do that if you ever look at the in the C constance