We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
hello there i have some problem regarding the bit shifting i want to convert the some no. from Hex. to Decimal for that i am going to used the shifting. when i recived the no. in hex format then i want to other reg. ex.when i recive 0x3d then i want to move the 3 to other location(or reg) after doing some calculation now i want move the d.with ACC >>(shifting opration is fine but in which way )please help me
"It is a single word or value, and , i tink its either hex ie, 0x3 , or decimal, 03d, cant be both right"
No - that is completely wrong!
"0x3D" is the standard 'C' notation for the hexadecimal number "3D" (which is 61 in decimal, and 00111101 in binary).
In this case, 'C' is not case-sensitive - so "0x3D" is equivalent to "0x3d", "0X3D", etc
all this is right but what about shifting
LowNibble = Number & 0x0F; HighNibble = Number >> 4;
When you said, "i think it's fine now", I thought that meant you'd got it!
LowNibble = Number & 0x0F; HighNibble = Number >> 4; with this i work for 0xFF,but what happened when my value excedded that "ex. for 0x270f which is equal to 9999 in decimal" what will i do in this case here is some way you just told me is it proper or not when i read this value form eeprom it get store in reg. say RDREG to seprate 0x270f first i am going >>8 so i will get 27 after that <<8 i will get 0f is it right
No once you shift the data is lost.
you did not say it was 16 bits. nibble1 = X & 0x000F nibble2 = (X >> 4) & 0x000F nibble3 = (X >> 8) & 0x000F nibble4 = (X >> 12) & 0x000F
Of course there are more efficient ways
No once you shift the data is lost. i am doing this all shifting operation by taking(copying) data in to different location. actully i am doing the conversion operation from hex to decimal that way i am seprating all these bit after that 0th bit multiply by 16^0 1st bit multiply by 16^1 2nd bit multiply by 16^2 3th bit multiply by 16^3 and after that adding all these hoping for the answer this one is long,and more complicated way if you are having any another way which is easy to understand and less complicated. please told me
nibble1 = multiply by 16^0 nibble2 = multiply by 16^1 nibble3 = multiply by 16^2 nibble4 = multiply by 16^3
sorry for above 2 post here you will get the clear view.
D_1 = nibble1 *16^0 D_2 = nibble2 *16^1 D_3 = nibble3 *16^2 D_4 = nibble4 *16^3
dec_ans = D_1 + D_2 + D_3 D_4