# How to convert hex from keyboard to ASCII for string

Page 1 of 1

## 9 Replies - 215 Views - Last Post: 24 September 2018 - 06:37 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=412819&amp;s=722d6a96ce1d8e7c280285907009d42b&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 LauriKiwi

Reputation: 0
• Posts: 6
• Joined: 24-September 18

# How to convert hex from keyboard to ASCII for string

Posted 24 September 2018 - 06:15 AM

Hello. I would like to know a simple solution to converting hex code from the keyboard to ASCII for a string.
If you have a solution, please explain it because I'm a noob.
I am working in independent x86 assembly.
Is This A Good Question/Topic? 0

## Replies To: How to convert hex from keyboard to ASCII for string

### #2 Programmer2004

Reputation: 18
• Posts: 96
• Joined: 25-October 17

## Re: How to convert hex from keyboard to ASCII for string

Posted 24 September 2018 - 06:20 AM

Do you want to convert that ASCII code to string representation like "0x4F" or to convert it to a character?

### #3 LauriKiwi

Reputation: 0
• Posts: 6
• Joined: 24-September 18

## Re: How to convert hex from keyboard to ASCII for string

Posted 24 September 2018 - 06:21 AM

Character, I guess.

### #4 Programmer2004

Reputation: 18
• Posts: 96
• Joined: 25-October 17

## Re: How to convert hex from keyboard to ASCII for string

Posted 24 September 2018 - 06:25 AM

Ok, now I understand, you want to add pressed character to string. To do that, you just insert the ASCII code in the string at the position where it should be. String is just an array of ASCII codes, and ASCII code is 1 byte, so every character in that string is 1 byte.

### #5 LauriKiwi

Reputation: 0
• Posts: 6
• Joined: 24-September 18

## Re: How to convert hex from keyboard to ASCII for string

Posted 24 September 2018 - 06:26 AM

Can you provide an example for that?

### #6 Programmer2004

Reputation: 18
• Posts: 96
• Joined: 25-October 17

## Re: How to convert hex from keyboard to ASCII for string

Posted 24 September 2018 - 06:28 AM

Sure, no problem, but first I need to know for what platform do you write your code?

### #7 LauriKiwi

Reputation: 0
• Posts: 6
• Joined: 24-September 18

## Re: How to convert hex from keyboard to ASCII for string

Posted 24 September 2018 - 06:31 AM

x86 assembly. Boots directly from BIOS.

Linux I forgot to add linux xD

Well that's what I'm coding on.

The code itself boots from BIOS or in this case QEMU.

### #8 Programmer2004

Reputation: 18
• Posts: 96
• Joined: 25-October 17

## Re: How to convert hex from keyboard to ASCII for string

Posted 24 September 2018 - 06:35 AM

Ok, so the platform is just an x86 PC without any operating system.

Alright, here's the example:

mov bx, 0 ;The BX register will be used for addressing

.stringLoop:
mov ah,0
int 0x16

;Save returned character to someString at offset BX
mov byte [someString + bx], al

;Increase BX to write next character at next position and repeat the loop
inc bx
jmp .stringLoop

someString db 0 ;This is the string variable

This is the shortest example I can think of. You can also add compare instructions which would end the loop when user presses the Enter key, etc., etc.

### #9 LauriKiwi

Reputation: 0
• Posts: 6
• Joined: 24-September 18

## Re: How to convert hex from keyboard to ASCII for string

Posted 24 September 2018 - 06:36 AM

Okay thanks!

### #10 Programmer2004

Reputation: 18
• Posts: 96
• Joined: 25-October 17

## Re: How to convert hex from keyboard to ASCII for string

Posted 24 September 2018 - 06:37 AM

You're welcome.