# Converting a number (I.e 123456) into letters

Watch
Announcements
#1
I can't work out how to convert a number (such as 123456) into letters (ABCDEFG) without importing ASCII.

Any help?
0
2 months ago
#2
(Original post by TheJazzPhysicist)
I can't work out how to convert a number (such as 123456) into letters (ABCDEFG) without importing ASCII.

Any help?
Eh? Do you mean converting to hex?
Or saying 1-26 is A-Z?

and what programming language you working in?
0
2 months ago
#3
(Original post by TheJazzPhysicist)
I can't work out how to convert a number (such as 123456) into letters (ABCDEFG) without importing ASCII.

Any help?
ASCII wouldn’t be much help if you’re trying to turn 1 into A, 2 into B ect… considering the numeric value for a capital A starts at 97. Though you could do some maths to make that number 1-26.

You’ll have to do this by first ensuring that your number is a string. Because you can’t perform string operations on an integer. You’ll then like have to iterate over each number in this string, and manually check its value. I’d personally use a switch statement for this:

Code:
```for(int i = 0; i < numberString.Length; i++) {
// Where i is the index of the number string (probably from a for-loop)
switch(numerString[i]) {
case ‘1’:
someNewString += ‘A’
break;
case '2':
someNewString += 'B'
break;
}
}```
Depending on what language you’re using you could either continuously concatenate onto an new empty string, or use the likes of a string builder. (Some languages may even allow you to change individual characters on the string itself).
Last edited by Strange5050; 2 months ago
0
2 months ago
#4
(Original post by TheJazzPhysicist)
I can't work out how to convert a number (such as 123456) into letters (ABCDEFG) without importing ASCII.

Any help?
Which language are you using?

Why do you think you need to "import" ASCII, and why is it a problem to do so?

Do you really mean an ASCII conversion? If 123456 = ABCDEFG then what is 26 in your system - is it BF or is it Z? Are you trying to represent all letters, or just a subset like A-G?

You can build a string like this: myalphabet = "ABCDEFGHIJK" (however long you want) and then use your individual digits to index into this (get a substring / slice depending on your language syntax).

1
X

new posts
Back
to top
Latest
My Feed

### Oops, nobody has postedin the last few hours.

Why not re-start the conversation?

see more

### See more of what you like onThe Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.

### Poll

Join the discussion

#### Are you travelling in the Uni student travel window (3-9 Dec) to go home for Christmas?

Yes (120)
28.1%
No - I have already returned home (57)
13.35%
No - I plan on travelling outside these dates (84)
19.67%
No - I'm staying at my term time address over Christmas (40)
9.37%
No - I live at home during term anyway (126)
29.51%

View All
Latest
My Feed

### Oops, nobody has postedin the last few hours.

Why not re-start the conversation?

### See more of what you like onThe Student Room

You can personalise what you see on TSR. Tell us a little about yourself to get started.