-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode.jl
More file actions
26 lines (23 loc) · 785 Bytes
/
Code.jl
File metadata and controls
26 lines (23 loc) · 785 Bytes
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
function generateBinaryString(n, max) # Strings of binary numbers from 00... to 11... of length n
return [string(i, base = 2, pad=n) for i in 0:max]
end
function OneCounter(string) # returns number of ones in decimal
count = 0
for i in string
if (i == '1')
count += 1
end
end
return count
end
n = 8
max = 2^n - 1
BinaryStrings = generateBinaryString(n, max)
open("TRACEFILE.txt","w") do file
for i in BinaryStrings
count = OneCounter(i) # Function returns number of ones in decimal
c = string(count, base = 2, pad = 4) # Convert count to binary
M = "1111" # Mask bit
write(file,"$i $c $M\n") # Writing in file
end
end