0% found this document useful (0 votes)
34 views2 pages

B2H Algorithm

The document describes algorithms for converting between binary coded decimal (BCD) and hexadecimal (HEX) numbers. It includes a main menu-driven algorithm that allows the user to choose between BCD to HEX and HEX to BCD conversion procedures. The BCD to HEX procedure takes a 5-digit BCD number as input and converts it to a 4-digit hexadecimal number. The HEX to BCD procedure performs the opposite conversion, taking a 4-digit hexadecimal number as input and producing a 5-digit BCD number as output.

Uploaded by

shanysunny
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views2 pages

B2H Algorithm

The document describes algorithms for converting between binary coded decimal (BCD) and hexadecimal (HEX) numbers. It includes a main menu-driven algorithm that allows the user to choose between BCD to HEX and HEX to BCD conversion procedures. The BCD to HEX procedure takes a 5-digit BCD number as input and converts it to a 4-digit hexadecimal number. The HEX to BCD procedure performs the opposite conversion, taking a 4-digit hexadecimal number as input and producing a 5-digit BCD number as output.

Uploaded by

shanysunny
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

BCD-HEX Conversion: Main Algorithm:

1. 2. 3. 4. 5. 6. 7. 8. 9.

Start. Display menu message to user. Get choice from user. If choice = 1 then perform BCD to HEX conversion. Call b2h procedure. If choice = 2 then perform HEX to BCD conversion. Call h2b procedure. If choice = 3 then exit from the given MENU. Stop.

Macros: 1. Name: disp 2. Purpose: Use macro to display the different messages 3. I/P: 09 function and 21H interrupt Procedures: h2b: 1. Name: HEX to BCD 2. Purpose: convert HEX no. into BCD. 3. I/P: 4 bit HEX number 4. Algorithm for Procedures i) Start ii) Get the 4-digit Hex number from the user. iii) Initialize 5 digit counter with initial value zero. iv) Check whether HEX no. is zero if yes go to step (viii). v) Decrement HEX no. by 1. vi) Add decimal 1 to counter. vii) Go to step (iv) viii) Display counter as BCD no. ix) Stop.

Procedures: b2h: 1. Name: BCD to HEX 2. Purpose: convert BCD no. into HEX. 3. I/P: 5 bit BCD number 4. Algorithm for Procedures i) Start ii) Get the 5-digit BCD number from the user. iii) Initialize 4 digit counter with initial value zero. iv) Check whether BCD no. is zero if yes go to step (viii). v) Subtract decimal 1 from BCD no. vi) Increment counter by 1. vii) Go to step (iv). viii) Display counter as HEX no. ix) Stop.

You might also like