TheJazzPhysicist
Badges: 13
Rep:
?
#1
Report Thread starter 4 weeks ago
#1
I can't work out how to convert a number (such as 123456) into letters (ABCDEFG) without importing ASCII.

Any help?
0
reply
MrSandyWilly
Badges: 18
Rep:
?
#2
Report 4 weeks 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
reply
Strange5050
Badges: 16
Rep:
?
#3
Report 4 weeks 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; 4 weeks ago
0
reply
davros
  • Study Helper
Badges: 16
Rep:
?
#4
Report 4 weeks 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).

Again, a bit more info on your ultimate goal would be helpful
1
reply
X

Quick Reply

Attached files
Write a reply...
Reply
new posts
Back
to top
Latest
My Feed

See more of what you like on
The Student Room

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

Personalise

Current uni students - are you thinking of dropping out of university?

Yes, I'm seriously considering dropping out (184)
14.23%
I'm not sure (59)
4.56%
No, I'm going to stick it out for now (380)
29.39%
I have already dropped out (37)
2.86%
I'm not a current university student (633)
48.96%

Watched Threads

View All