![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
#include "C:\javatest\str1.h"
#include "input.c" void main() { int8 data1, data2; int16 data; while (1){ printf("press any key...\n\r"); //getch(); data1 = gethex(); data2 = gethex(); data = data1 << 8 + data2; printf("...data %4x \n\r", data); } } I want to get a double byte figure from user input, but it shows 0000 instead of 4-digit(hex). So, is there any better way to accept double/multiple byte from user input? |
|
|
|
|
|
|
(permalink) | |
|
Quote:
happening might be because the x format specifier is expecing an int or unsigned (in your case maybe an int32). As a result it is reading the low/high word depending on the endianess of your machine, which may not be what you want. You could try to set data to an int32 type or better yet an unsigned since in this case, you just want the hex value. |
||
|
|
|
|
|
(permalink) |
|
gethex - get-hex is a function in input.h.
I want to do something like, let's say, when the user input 1234 or perhaps, 12345678 the system will take the whole string as hex number. |
|
|
|
|
|
|
(permalink) |
|
in your code, data1 is declared as int8
so, your instruction of "data1<<8" is probably make the entire byte become zero, as 8 zero shifted in maybe u can try this data=data1; data<<=8; |
|
|
|
|