歴群の最新号、読み応えのある記事がたくさんあったけどラジオ体操の話が面白かった:)
歴史群像 2015年 10 月号 [雑誌]
Language Design: Building a Modern C, Round 1 – owensd.io
When I think about building a modern C language, there really are just a set of a few things I’m thinking:
で、
Language Design: Building a Modern C, Round 1 – owensd.io
#include <stdio.h>
#include <stdlib.h>
int main(int ArgumentCount, char** ArgumentValues) {
if (ArgumentCount != 2) {
printf("Invalid usage!\n");
return -1;
}
printf("compiling file: %s\n", ArgumentValues[1]);
FILE *InputFile = fopen(ArgumentValues[1], "r");
if (InputFile == 0) {
printf("Unable to open file.\n");
return -1;
}
fseek(InputFile, 0L, SEEK_END);
long FileLength = ftell(InputFile);
rewind(InputFile);
char *FileBuffer = (char *)malloc(sizeof(char) * (FileLength + 1));
if (FileBuffer == 0) {
printf("Unable to allocate memory for the file buffer.\n");
return -1;
}
if (fread(FileBuffer, 1, FileLength, InputFile) != FileLength) {
printf("Unable to read the entire file.\n");
return -1;
}
FileBuffer[FileLength] = '\0';
printf("file size: %ld\n", FileLength);
printf("file contents: \n%s\n", FileBuffer);
fclose(InputFile);
return 0;
}
Language Design: Building a Modern C, Round 1 ? owensd.io
import stdlib
let arguments = environment.arguments
guard if arguments.count != 2:
println "Invalid usage!"; exit -1
let filename = arguments[1]
println "compiling file: {0}\n" filename
guard let file = sys.io.fopen filename sys.io.flags.read:
println "Unable to open file."; exit -1
guard let content = sys.io.read file:
println "Unable to read the entire file."; exit -1
println "file size: {0}" file.size
println "file contents: \n{0}" content</pre>
© 2015 David Owens II. Powered by Jekyll using the Minimal Mistakes theme.
上位8ビットを取り出してそれを3ビット右シフト。
を、11ビット右シフトに置き換えてちょっとごにょごにょ。
0.upto(99) {|n|
printf "%2d %2d %2d\n", n, n/10, (n*205)>>11
}
>ruby div10.rb
0 0 0
1 0 0
2 0 0
3 0 0
4 0 0
5 0 0
6 0 0
7 0 0
8 0 0
9 0 0
10 1 1
11 1 1
12 1 1
13 1 1
14 1 1
15 1 1
16 1 1
17 1 1
18 1 1
19 1 1
20 2 2
21 2 2
22 2 2
23 2 2
24 2 2
25 2 2
26 2 2
27 2 2
28 2 2
29 2 2
30 3 3
31 3 3
32 3 3
33 3 3
34 3 3
35 3 3
36 3 3
37 3 3
38 3 3
39 3 3
40 4 4
41 4 4
42 4 4
43 4 4
44 4 4
45 4 4
46 4 4
47 4 4
48 4 4
49 4 4
50 5 5
51 5 5
52 5 5
53 5 5
54 5 5
55 5 5
56 5 5
57 5 5
58 5 5
59 5 5
60 6 6
61 6 6
62 6 6
63 6 6
64 6 6
65 6 6
66 6 6
67 6 6
68 6 6
69 6 6
70 7 7
71 7 7
72 7 7
73 7 7
74 7 7
75 7 7
76 7 7
77 7 7
78 7 7
79 7 7
80 8 8
81 8 8
82 8 8
83 8 8
84 8 8
85 8 8
86 8 8
87 8 8
88 8 8
89 8 8
90 9 9
91 9 9
92 9 9
93 9 9
94 9 9
95 9 9
96 9 9
97 9 9
98 9 9
99 9 9
ふむ。
X * 205 / 2^11 で、
その 2^11 は 2048だから。ってことね。