[英]Get specific hex from M68k ram address with C language
I've got a new question related to this other one, which is solved Get specific byte from M68k ram address with C language 我有一个与此其他问题相关的新问题,该问题已解决, 使用C语言从M68k内存地址中获取特定字节
Now my address has a full row of: 现在,我的地址已满满:
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
which are hexadecimals. 是十六进制的。
If I tried with the same pattern of the other question, I can't get the value displayed by printf... this is what I've done: 如果我尝试使用其他问题的相同模式,则无法获得printf显示的值...这是我所做的:
char* REG_SW;
REG_SW = (char*)0x300123;
then: 然后:
printf("H DIP SWITCHES: %d", REG_SW[0])
gives me -1 给我-1
Thanks in advance and Merry XMas!! 在此先感谢,并祝圣诞快乐!
In order to print the char
value in hex form use 为了以十六进制格式打印
char
值,请使用
printf("H DIP SWITCHES: %02X", REG_SW[0])
Look here for printf
tutorial, but the essence in our case is using the X
format specifier having value printed in hex form 2 bytes wide (this is what behind the format width 02
) 在这里查看
printf
教程,但是在我们的案例中,本质是使用X
格式说明符,其值以2字节宽的十六进制形式打印(这是格式宽度02
含义)
EDIT- as chux observed in his comment to the question its crucial treating the register value as an unsigned type one 编辑-正如chux在他对该问题的评论中观察到的那样,将寄存器值视为一个无符号类型是至关重要的
unsigned char* REG_SW (unsigned char*) 0x300123;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.