Julia 언어 소스:
## Filename: testHexView_02.jl
##
## Purpose: Show the hexadecimal codes of the given binary file.
##
## Set Env: set path=d:\julia;%path%
## Execute: julia testHexView_02.jl [filename]
##
## Date: 2013. 8. 4.
function printUsage()
@printf("Using: julia testHexView_02.jl [filename]\n")
end
function toHex(b)
s = ""
x1 = (b & 0xF0) >> 4
x2 = b & 0x0F
if x1 > 9
s = s * char(int('A') + (x1 - 10))
else
s = s * char(int('0') + x1)
end
if x2 > 9
s = s * char(int('A') + (x2 - 10))
else
s = s * char(int('0') + x2)
end
return s
end
function toHex8(n)
s = ""
x2 = (n & 0xF000000) >> 24
x3 = (n & 0xF00000) >> 20
x4 = (n & 0xF0000) >> 16
x5 = (n & 0xF000) >> 12
x6 = (n & 0xF00) >> 8
x7 = (n & 0xF0) >> 4
x8 = n & 0x0F
s = "0"
if x2 < 10
s = s * char(int('0') + x2)
else
s = s * char(int('A') + (x2 - 10))
end
if x3 < 10
s = s * char(int('0') + x3)
else
s = s * char(int('A') + (x3 - 10))
end
if x4 < 10
s = s * char(int('0') + x4)
else
s = s * char(int('A') + (x4 - 10))
end
s = s * " "
if x5 < 10
s = s * char(int('0') + x5)
else
s = s * char(int('A') + (x5 - 10))
end
if x6 < 10
s = s * char(int('0') + x6)
else
s = s * char(int('A') + (x6 - 10))
end
if x7 < 10
s = s * char(int('0') + x7)
else
s = s * char(int('A') + (x7 - 10))
end
if x8 < 10
s = s * char(int('0') + x8)
else
s = s * char(int('A') + (x8 - 10))
end
return s
end
# 실행 시작 지점
if length(ARGS) < 1
printUsage()
exit(1)
end
fname = ARGS[1]
f = open(fname)
data = read(f, Int8)
seek_end(f)
fsize = position(f)
seek(f, 0)
@printf("The size of the file \"%s\" is %d.\n\n", fname, fsize)
n = 0
t = ""
for i = 1: fsize
if n % 16 == 0
@printf("%s: ", toHex8(n))
end
c = read(f, Int8)
@printf(" %s", toHex(c))
if c < int8(' ') || c > 0x7F
t *= "."
else
t *= char(c)
end
n += 1
if n % 16 == 0
@printf(" |%s|\n", t)
t = ""
end
end
if t != ""
for i = 1: (16 - (n % 16))
@printf(" ")
end
@printf(" |%s", t)
for i = 1: (16 - (n % 16))
@printf(" ")
end
@printf("|\n")
end
close(f)
@printf("\nRead %d bytes.\n", n)
실행하기 예 1> julia testHexView_02.jl temp_1.bin
The size of the file "temp_1.bin" is 12.
0000 0000: 48 65 6C 6C 6F 20 74 68 65 72 65 0A |Hello there. |
Read 12 bytes.
실행하기 예 2> julia testHexView_02.jl myFile.ser
The size of the file "myFile.ser" is 130.
0000 0000: AC ED 00 05 73 72 00 06 50 65 72 73 6F 6E 07 31 |....sr..Person.1|
0000 0010: 46 DB A5 1D 44 AB 02 00 03 49 00 03 61 67 65 4C |F...D....I..ageL|
0000 0020: 00 09 66 69 72 73 74 4E 61 6D 65 74 00 12 4C 6A |..firstNamet..Lj|
0000 0030: 61 76 61 2F 6C 61 6E 67 2F 53 74 72 69 6E 67 3B |ava/lang/String;|
0000 0040: 4C 00 08 6C 61 73 74 4E 61 6D 65 71 00 7E 00 01 |L..lastNameq.~..|
0000 0050: 78 70 00 00 00 13 74 00 05 4A 61 6D 65 73 74 00 |xp....t..Jamest.|
0000 0060: 04 52 79 61 6E 73 71 00 7E 00 00 00 00 00 1E 74 |.Ryansq.~......t|
0000 0070: 00 07 4F 62 69 2D 77 61 6E 74 00 06 4B 65 6E 6F |..Obi-want..Keno|
0000 0080: 62 69 |bi |
Read 130 bytes.
'프로그래밍 > Julia' 카테고리의 다른 글
Julia 언어로 평방근, 입방근, n제곱근 구하는 함수를 구현하고 테스트하기 (0) | 2013.03.07 |
---|---|
Julia 언어로 역삼각함수, 역쌍곡선함수 값을 구하는 예제 (0) | 2013.03.07 |
감마함수(gamma function)의 값을 (유효수자 15자리 까지 정밀하게) 계산하는 Julia 언어 소스 (0) | 2013.03.07 |
조립제법(Horner의 방법) 예제 2 for Julia (0) | 2013.03.07 |
숫자 맞추기 게임 with Julia (0) | 2013.03.06 |