How can I improve this C program for Hexadecimal to decimal conversion? How can I convert from decimal to hexadecimal in C language? Write a program that will prompt the user to enter a hex digit character ('0'. 'F'), display it on the next line in decimal, and ask the user i.i he or she.
Converting Hex to BCD sounds simple, but I've been trying to figure this out for hours without much to show for the effort (a search didn't reveal anything very helpful either).
I'm trying to convert a Hex number to a BCD number in Assembly, programming a Motorola M68HC12 microcontroller. (I need the BCD for outputting a 2-digit number to a pair of 7-segment LED displays connected to one of the ports). Hex to BCD is easy if I do it, but trying to get the HC-12 to do it is another matter. Problem is that the starting number, calculations, and result all have to be in hex. The output number has to look like BCD while actually being hex.
For example:
(starting number) (convert to)
00h 00h
05h 05h
0Ah 10h
0Fh 15h
14h 20h
19h 25h
1Eh 30h
...
(starting number) (convert to)
00h 00h
05h 05h
0Ah 10h
0Fh 15h
14h 20h
19h 25h
1Eh 30h
...
This only has to work on the numbers 0 through 59. Trying multiple ideas and subroutines, I managed to come up with one that works on numbers from (0-39), (42-47) but other numbers are messed up (obviously a faulty algorithm). I feel that I'm missing something obvious here, but can't think what it might be.
The algorithim that works on some numbers (so you can see what direction my thoughts have been taking):
seperate 2 hex digits (take upper and lower nibble of byte)
if lower > 9 add 6 to it
multiply higher by 16
add 2 togeather
decimal adjust answer
seperate 2 hex digits (take upper and lower nibble of byte)
if lower > 9 add 6 to it
multiply higher by 16
add 2 togeather
decimal adjust answer
Decimal Adjust (op code daa) is meant to be used after adding 2 BCD numbers togeather, so I'm not supposed to be using it in this case. Probably why it only 'almost' works.
Any help would be appreciated. If I can't figure this out I'll have to give up and write the program the easy way (store number in BCD to start with and use daa after each add/subtract operation).
Convert Hex. to Decimal
Convert Hex. to Decimal
I am studying computing science at university and i am having problems with the following homework
I'm hoping someone will be able to help me out.
HOMEWORK
Develop an emmbedded intel 8086 assembler program in stages to solve the following problem
Convert a string containing an unsigned integer as a sequence of hexidecimal character digits to another string containing the corresponding decimal character digits within the assembler, without using any logical operations (AND,OR,XOR,shift), without using multiplication or division operations and without using a straight sequence of simple 4 repeated ADD operations to achieve multiplication.
The Pascal section will only input the original string and print the result.
(assume that the maximum hex. input number is 7FFF. use only 8-bit and 16-bit registers, except for the 32-bit string address register.)
You may find it helpful to use internal procedure calls in the assembler, which jump to a section of code with a label and which returns to the assembler statment after the call
CALL @POINT {call procedure POINT}
....
@POINT NOP {start of procedure}
....
RET {return from procedure}
I have 3 days left before I have to hand it in.
Cheers Steve
I'm hoping someone will be able to help me out.
HOMEWORK
Develop an emmbedded intel 8086 assembler program in stages to solve the following problem
Convert a string containing an unsigned integer as a sequence of hexidecimal character digits to another string containing the corresponding decimal character digits within the assembler, without using any logical operations (AND,OR,XOR,shift), without using multiplication or division operations and without using a straight sequence of simple 4 repeated ADD operations to achieve multiplication.
The Pascal section will only input the original string and print the result.
(assume that the maximum hex. input number is 7FFF. use only 8-bit and 16-bit registers, except for the 32-bit string address register.)
You may find it helpful to use internal procedure calls in the assembler, which jump to a section of code with a label and which returns to the assembler statment after the call
CALL @POINT {call procedure POINT}
....
@POINT NOP {start of procedure}
....
RET {return from procedure}
I have 3 days left before I have to hand it in.
Cheers Steve