Julia lang ,看這名字就值得學習一下。學了一段時間,寫一個稍微像樣一點的程式練練手吧。
#using printstyled
# printing text in different colors
#for color in [:red, :cyan, :blue, :magenta]
# printstyled("Hello World $(color) "; color = color)
#end
using Printf
#也可以修改成透過引數的形式傳入
io1 = open("d:\\test.clj")
io2 = open("d:\\test.rb")
data1 = Array{UInt8}(undef, 16)
data2 = Array{UInt8}(undef, 16)
l1 = readbytes!(io1, data1, 16)
l2 = readbytes!(io2, data2, 16)
addr = 0
while l1 > 0 || l2 >0
Printf.@printf("%08x ", addr)
for i = 1:16
if l1 > i
if (i < l2 && data1[i] != data2[i]) || (i >= l2)
printstyled(Printf.@sprintf("%02x ", data1[i]); color = :red)
else
printstyled(Printf.@sprintf("%02x ", data1[i]); color = :blue)
end
else
print(" ")
end
end
for i = 1:16
if l2 > i
if (i < l1 && data1[i] != data2[i]) || (i >= l1)
printstyled(Printf.@sprintf("%02x ", data2[i]); color = :red)
else
printstyled(Printf.@sprintf("%02x ", data2[i]); color = :blue)
end
else
print(" ")
end
end
print("\n")
global l1 = readbytes!(io1, data1, 16)
global l2 = readbytes!(io2, data2, 16)
global addr += 16
end
close(io1)
close(io2)
結果如下: