如何将字母表转换为数字? [英] How to convert alphabet to numbers?

查看:414
本文介绍了如何将字母表转换为数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新手在这里..需要一些帮助..


字母有26个字符n每个角色都有秘密号码..


例如:a = 01

im newbie here.. n need some help..

alphabets got 26 character n each character got secret number..

example: a = 01

推荐答案

字符已经可以通过ASCII标准直接转换为整数, http://asciitable.com/ 有转化。要快速获得a-> 1等,从给定字符中减去''a'并添加1.


您还可以使用所有字符的数组,这将是使a-> 00和z-> 25,因为数组是零索引的。要得到a-> 01,只需用一些不会被使用的控制字符填充数组,也许是一个数字。


如果你经过某种替换加密,这些解决方案中的任何一个都可以很容易地使用,因为后者可以很容易地在全局范围内声明,前者允许直接操作。

Characters are already directly convertible to integers via the ASCII standard, http://asciitable.com/ has the conversions. To quickly get a->1 and such, subtract ''a'' from a given character and add 1.

You can also use an array of all the characters, which would make a->00 and z->25, since arrays are zero-indexed. To get a->01, just pad the array with some control character that won''t be used, maybe a number.

If you''re after some sort of substitution encryption, either of these solutions will be fairly easy to work with, as the latter can easily be declared in global scope and the former allows direct manipulation.

展开 | 选择 | Wrap | 行号


我知道ASCII标准,但你可以教我如何在turbo c中应用ASCII码。


如果a = 01,b = 02,c = 03



i几乎要做这个... huhuh ...
i know about ASCII standard but can u teach me how to apply ASCII code in turbo c.

if a=01,b=02,c=03

when i type "abc" the answer should be 010203

i almost giv up doing this.. huhuh...


如果你想直接链接a-> ; 01,使用std :: map< char,int>。这可能会更好地满足您的需求,因为它允许您轻松更改给定字符映射到的数字。
If you want a direct way to link a->01, use a std::map<char, int>. That might fit your needs a little better, as it allows you to easily change the number a given character is mapped to.


这篇关于如何将字母表转换为数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆