1 | #include <fstream.hfa> |
---|
2 | int main() { |
---|
3 | int128 x = 0xffff, y = 0x2; |
---|
4 | x <<= 64; |
---|
5 | x += 0xffff; |
---|
6 | y <<= 64; |
---|
7 | y += 0123; |
---|
8 | y |= 0x8000000000000000; |
---|
9 | x = -x; |
---|
10 | sout | x; |
---|
11 | sout | sign(x); |
---|
12 | x = -x; |
---|
13 | sout | sign(x); |
---|
14 | sout | nl; |
---|
15 | #if 1 |
---|
16 | sout | bin(x); |
---|
17 | sout | upcase(bin(x)); |
---|
18 | sout | nobase(bin(x)); |
---|
19 | sout | wd( 95, upcase(bin(x)) ); |
---|
20 | sout | wd( 95,90, upcase(bin(x)) ); |
---|
21 | sout | wd( 25,30, upcase(hex(x)) ); |
---|
22 | sout | nl; |
---|
23 | |
---|
24 | printf( "%#.10o\n", 0123 ); |
---|
25 | sout | wd( 1,10, oct(0123) ); |
---|
26 | sout | oct(x); |
---|
27 | sout | nobase(oct(x)); |
---|
28 | sout | wd( 45, oct(0123) ); |
---|
29 | sout | wd( 45,40, oct(0123) ); |
---|
30 | sout | wd( 40,45, oct(0123) ); |
---|
31 | sout | wd( 45, oct(x) ); |
---|
32 | sout | wd( 45,40, oct(x) ); |
---|
33 | sout | wd( 40,45, oct(x) ); |
---|
34 | |
---|
35 | sout | left(wd( 45, oct(0123) )) | 'X'; |
---|
36 | sout | left(wd( 45, oct(x) )) | 'X'; |
---|
37 | sout | left(wd( 45, oct(y) )) | 'X'; |
---|
38 | sout | left(wd( 45,40, oct(0123) )) | 'X'; |
---|
39 | sout | left(wd( 45,40, oct(x) )) | 'X'; |
---|
40 | sout | left(wd( 45,40, oct(y) )) | 'X'; |
---|
41 | sout | left(wd( 40,45, oct(0123) )) | 'X'; |
---|
42 | sout | left(wd( 40,45, oct(x) )) | 'X'; |
---|
43 | sout | left(wd( 40,45, oct(y) )) | 'X'; |
---|
44 | printf( "%#-1.10oX\n", 0123 ); |
---|
45 | sout | left(wd( 1,10, oct(0123) )) | 'X'; |
---|
46 | printf( "%#-40.10oX\n", 0123 ); |
---|
47 | sout | left(wd( 40,10, oct(0123) )) | 'X'; |
---|
48 | sout | left(wd( 40,10, oct(x) )) | 'X'; |
---|
49 | sout | left(wd( 40,10, oct(y) )) | 'X'; |
---|
50 | sout | left(wd( 10,40, oct(0123) )) | 'X'; |
---|
51 | sout | left(wd( 10,40, oct(x) )) | 'X'; |
---|
52 | sout | left(wd( 10,40, oct(y) )) | 'X'; |
---|
53 | |
---|
54 | y = 01234567; |
---|
55 | sout | left(wd( 45, 49, oct(y) )) | 'X'; |
---|
56 | y = -y; |
---|
57 | sout | wd(0, oct(y)) | 'Y'; |
---|
58 | sout | left(wd(0, oct(y))) | 'Y'; |
---|
59 | sout | nl; |
---|
60 | |
---|
61 | sout | hex(x); |
---|
62 | sout | upcase(hex(x)); |
---|
63 | sout | nobase(hex(x)); |
---|
64 | sout | wd( 45, upcase(hex(x)) ); |
---|
65 | sout | wd( 45,40, upcase(hex(x)) ); |
---|
66 | sout | wd( 45,49, upcase(hex(x)) ); |
---|
67 | sout | left(wd( 45, upcase(hex(x)) )) | 'X'; |
---|
68 | sout | left(wd( 45,40, upcase(hex(x)) )) | 'X'; |
---|
69 | sout | left(wd( 45,49, upcase(hex(x)) )) | 'X'; |
---|
70 | |
---|
71 | sout | nl; |
---|
72 | |
---|
73 | int128 divisor = 0x4b3b4ca85a86c47a; |
---|
74 | divisor <<= 16; |
---|
75 | divisor += 0x98a224000000000; |
---|
76 | |
---|
77 | // base 2 |
---|
78 | sout | "base 2"; |
---|
79 | sout | bin(divisor); |
---|
80 | sout | upcase(bin(divisor)); |
---|
81 | sout | wd(38, upcase(bin(divisor))); |
---|
82 | sout | wd(40, upcase(bin(divisor))); |
---|
83 | sout | wd(40, 38, upcase(bin(divisor))); |
---|
84 | sout | wd(40, 30, upcase(bin(divisor))); |
---|
85 | sout | pad0(sign(wd(40, 38, upcase(bin(divisor))))); |
---|
86 | sout | nl; |
---|
87 | |
---|
88 | // oct |
---|
89 | sout | "base 8"; |
---|
90 | sout | upcase(oct(divisor)); |
---|
91 | sout | wd(38, upcase(oct(divisor))); |
---|
92 | sout | wd(40, upcase(oct(divisor))); |
---|
93 | sout | wd(40, 38, upcase(oct(divisor))); |
---|
94 | sout | wd(40, 30, upcase(oct(divisor))); |
---|
95 | sout | pad0(sign(wd(40, 38, upcase(oct(divisor))))); |
---|
96 | sout | nl; |
---|
97 | |
---|
98 | // decimal |
---|
99 | sout | "base 10"; |
---|
100 | sout | divisor; |
---|
101 | sout | wd(2, divisor); |
---|
102 | sout | wd(3, divisor); |
---|
103 | sout | wd(10, divisor); |
---|
104 | sout | wd(24, divisor); |
---|
105 | sout | wd(38, divisor); |
---|
106 | sout | wd(39, divisor); |
---|
107 | sout | wd(40, divisor); |
---|
108 | |
---|
109 | sout | wd(40, 30, divisor); |
---|
110 | sout | wd(40, 38, divisor); |
---|
111 | sout | wd(40, 40, divisor); |
---|
112 | sout | pad0(wd(40, divisor)); |
---|
113 | sout | pad0(sign(wd(40,divisor))); |
---|
114 | sout | nl; |
---|
115 | |
---|
116 | // hex |
---|
117 | sout | "base 16"; |
---|
118 | sout | upcase(hex(divisor)); |
---|
119 | sout | wd(38, upcase(hex(divisor))); |
---|
120 | sout | wd(40, upcase(hex(divisor))); |
---|
121 | sout | wd(40, 38, upcase(hex(divisor))); |
---|
122 | sout | wd(40, 30, upcase(hex(divisor))); |
---|
123 | sout | pad0(sign(wd(40, 38, upcase(hex(divisor))))); |
---|
124 | sout | nl; |
---|
125 | |
---|
126 | |
---|
127 | sout | bin(divisor); |
---|
128 | sout | upcase(bin(divisor)); |
---|
129 | sout | oct(divisor); |
---|
130 | sout | hex(divisor); |
---|
131 | sout | upcase(hex(divisor)); |
---|
132 | sout | nobase(bin(divisor)) | nobase(oct(divisor)) | nobase(hex(divisor)); |
---|
133 | sout | sign(divisor); |
---|
134 | sout | -divisor; |
---|
135 | sout | sign(-divisor); |
---|
136 | sout | wd(2, divisor); |
---|
137 | sout | wd(3,10,divisor); |
---|
138 | sout | left(wd(40,divisor)) | 'X'; |
---|
139 | sout | left(sign(wd(40, divisor))) | 'X'; |
---|
140 | sout | left(sign(wd(0,40, divisor))) | 'X'; |
---|
141 | printf( "%-+1.40dX\n", 123456789 ); |
---|
142 | #endif // 0 |
---|
143 | } |
---|