#Booth's algorithm
-13 * 9 = -117
-13 = 10011
9 = 01001
# based on https://gist.github.com/daviddalpiaz/ae62ae5ccd0bada4b9acd6dbc9008706 | |
# load image files | |
load_image_file = function(filename) { | |
f = gzfile(filename, 'rb') | |
readBin(f, 'integer', n = 1, size = 4, endian = 'big') | |
n = readBin(f, 'integer', n = 1, size = 4, endian = 'big') | |
nrow = readBin(f, 'integer', n = 1, size = 4, endian = 'big') | |
ncol = readBin(f, 'integer', n = 1, size = 4, endian = 'big') | |
x = readBin(f, 'integer', n = n * nrow * ncol, size = 1, signed = FALSE) |
// truth table POC | |
let vars = ['x1', 'x2', 'x3', 'x4'], | |
r = Math.pow(2, vars.length), | |
str = '', | |
i, | |
j; | |
str += `\r\n\r\n` | |
for (i = 0; i < vars.length; i++) { |
q1 | |
qAccept | |
qReject | |
0,1 | |
q1 (0,x,R) q2 | |
q1 (y,y,R) q4 | |
q1 ( , ,L) qAccept | |
q1 (1, ,R) qReject | |
q2 (0,0,R) q2 | |
q2 (y,y,R) q2 |
dfa_start(dfa1, q0). | |
dfa_final(dfa1, q3). | |
dfa_transition(dfa1, q0, '0', q1). | |
dfa_transition(dfa1, q0, '1', q1). | |
dfa_transition(dfa1, q0, '.', q2). | |
dfa_transition(dfa1, q1, '0', q1). | |
dfa_transition(dfa1, q1, '1', q1). | |
dfa_transition(dfa1, q1, '.', q3). | |
dfa_transition(dfa1, q2, '0', q3). |
module Dfa | |
( | |
stateFactory | |
, alphabet | |
, allStates | |
, firstState | |
, acceptStates | |
, allTransitions | |
, transFromState | |
, transLabel |