# Can't understanding the shifting of alphabet letters using ASCII

Page 1 of 1

## 2 Replies - 1779 Views - Last Post: 12 March 2013 - 03:24 PMRate 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=315103&amp;s=8d1ba17777f18ebedc1ab97f5e7c70b3&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 CrazyPanda

Reputation: 0
• Posts: 2
• Joined: 11-March 13

# Can't understanding the shifting of alphabet letters using ASCII

Posted 11 March 2013 - 03:20 PM

Can someone please explain how the code/formula below shifts the alphabet letters by a certain number and avoids the error of going over the alphabet if for example the letter to be shifted is Z and the amount to shift is more than 0

For lowercase letters:
```NewASCIICode = ((26 + OldASCIICode - Asc("a") + AmountToShift) Mod 26) + Asc("a")
```

For uppercase letters:
```NewASCIICode = ((26 + OldASCIICode - Asc("A") + AmountToShift) Mod 26) + Asc("A")
```

Would be great if anyone could explain how this is done, I tried googling it, but I just found the code without a proper explanation.

Is This A Good Question/Topic? 0

## Replies To: Can't understanding the shifting of alphabet letters using ASCII

• MrCupOfT

Reputation: 2298
• Posts: 9,535
• Joined: 29-May 08

## Re: Can't understanding the shifting of alphabet letters using ASCII

Posted 11 March 2013 - 03:29 PM

Break it down into it constituent parts.
What does each part do?

Now which aspect does the wrap around?

### #3 CrazyPanda

Reputation: 0
• Posts: 2
• Joined: 11-March 13

## Re: Can't understanding the shifting of alphabet letters using ASCII

Posted 12 March 2013 - 03:24 PM

AdamSpeight2008, on 11 March 2013 - 03:29 PM, said:

Break it down into it constituent parts.
What does each part do?

Now which aspect does the wrap around?

Thank you for not giving me the solution straightaway . After a couple of times failing and finding the simpler formula on Wikipedia, I understood how this works.

However, one thing I still not sure about is the +26 at the beginning of the formula, is it really needed in this case? Since 26 Mod 26 = 0, doesn't (26 + AnyNumber) Mod 26 equal to just the AnyNumber? I tried removing it, and the code still works, but I'm not sure if it creates bugs or not, can you clarify if I'm correct or not, please?

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }