-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomptest.c
53 lines (45 loc) · 1.05 KB
/
comptest.c
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
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
// Based on http://svn.so-much-stuff.com/svn/trunk/pdp8/src/decus/5,8-25/decus-5-25.pdf
void printBits(size_t const size, void const * const ptr) {
unsigned char *b = (unsigned char*) ptr;
unsigned char byte;
int i, j;
for (i=size-1;i>=0;i--)
{
for (j=7;j>=0;j--)
{
byte = (b[i] >> j) & 1;
printf("%u", byte);
}
printf(",");
}
}
uint32_t signExtend24(uint32_t v) {
if (v&0x00800000) v=v|0xFF800000;
else v=v&~0xFF800000;
return v;
}
uint16_t rnd12(void) {
static uint64_t num=1;
num=num*(131072+3);
return (num>>24)&4095;
}
int32_t rnd24(void) {
uint16_t a,b;
uint32_t c;
a=rnd12() & 06003;
b=rnd12() & 06003;
c=(a<<12)+b;
c=signExtend24(c);
return c;
}
int main(void) {
for (int i=0; i<1000000; i++) {
int32_t a,b;
a=rnd24();
b=rnd24();
printf("% 08d % 08d %d%d%d%d%d%d\n",a, b, a==b, a>=b, a>b, a!=b, a<=b, a<b);
}
}