# 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
1 month 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
1 month 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; 1 month ago
0
1 month 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

#### Should there be a new university admissions system that ditches predicted grades?

No, I think predicted grades should still be used to make offers (534)
33.99%
Yes, I like the idea of applying to uni after I received my grades (PQA) (647)
41.18%
Yes, I like the idea of receiving offers only after I receive my grades (PQO) (318)
20.24%
I think there is a better option than the ones suggested (let us know in the thread!) (72)
4.58%