Write hex numbers stored as strings to hex file directly in Java? -
i'm writing small assembler in java converts arm assembly code hex file executed virtual arm cpu on fpga.
for example
sub r0, r15, r15 add r2, r0, #5 add r3, r0, #12 sub r7, r3, #9
will translated machine(hex) code as
e04f000f e2802005 e280300c e2437009
which stored strings line line in string array output
in code.
so how can write machine code hex file exactly literally is? instead of being encoded text.
so when open output file tools hexeditor show encoding (without newline sign of course...)
e0 4f 00 0f e2 80 20 05 e2 80 30 0c e2 43 70 09
currently tried:
outputstream os = new fileoutputstream("hexcode.hex"); (string s : output) { int value = integer.decode(s); os.write(value); } os.close();
but gives me errors
exception in thread "main" java.lang.numberformatexception: input string:"e04f000f" @ java.lang.numberformatexception.forinputstring(numberformatexception.java:65) @ java.lang.integer.parseint(integer.java:580) @ java.lang.integer.valueof(integer.java:740) @ java.lang.integer.decode(integer.java:1197) @ assembler.assembler.main(assembler.java:220)
any help? million thanks!
use integer.parseint(s, 16)
instead of integer.decode(string)
"16" tells it hex-string
Comments
Post a Comment