Sign in to follow this  
Followers 0
E1M1

Need number to char help

29 posts in this topic

#1 ·  Posted (edited)

I need to convert number to char.

1=A

26=Z

27=AA

By what logic i can convert random int to A-Z string?

I cant find any logig.

Edited by E1M1

edited

Share this post


Link to post
Share on other sites



E1Mi,

Perhaps something like this: ;)

$iInt = InputBox("Enter a Number", "Just a number from 1 to 676")

$iSecond = Mod($iInt, 26)
$iFirst = Int($iInt / 26)

$sLetters = ""
If $iFirst > 0 Then $sLetters &= Chr($iFirst + 64)
$sLetters &= Chr($iSecond + 64)

ConsoleWrite($sLetters  & @CRLF)

Lots of work for you still to do, but it gives you the idea. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Hang on... In theory, you are talking about a numerical base with a letter notation. Base 26 in this case. When you think of it that way, it makes it more logical:

Func ToBase26($i)
    Local $s = ""

    Do
        $s = Chr(Mod($i, 26) + 64) & $s
        $i = Int($i / 26)
    Until $i = 0

    Return $s
EndFunc   ;==>ToBase26

That was based on WBD's (pity he hasn't been around recently) code here: http://www.autoitscript.com/forum/index.php?showtopic=93742

I'm sure he posted a better version with _FromBase somewhere... Got the link Melba?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Something like this?

ConsoleWrite(N2C(28) & @CRLF)

Func N2C($int)
    Local $j, $char, $m

    For $j = 1 To Ceiling($int / 26)
        $m = Mod($int, 26)
        If Not $m Then
            $char &= Chr(90) ;"Z"
        Else
            $char &= Chr(64 + $m)
        EndIf
    Next
    Return $char
EndFunc

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Func ToBase26($i)
    Local $s = ""

    Do
        $s = Chr(Mod($i, 26) + 64) & $s
        $i = Int($i / 26)
    Until $i = 0

    Return $s
EndFunc   ;==>ToBase26

Does anyone know why 26 doesnt return Z wuth this func? all other numbers seems working, just 26 is problematic.

UEZ's func also doesn like 26


edited

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

What would zero be in this base? ;) Think about that for a bit.

One possible solution:

Func ToBase26($i)
    Local $s = ""

    Do
        $s = Chr(Mod($i, 26) + 64) & $s
        $i = Int($i / 27)
    Until $i = 0

    Return StringReplace($s, "@", "Z")
EndFunc   ;==>ToBase26

Edited by Mat

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Indeed, did not keep in mind the 0 base. ;)

Update above.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

ok now why 28 is BB and not AB? it should go like aa, ab ac...az ... aaa,aab,aac....

Looks like i didnt express myself clearly enough at the beginning.


edited

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

ok now why 28 is BB and not AB? it should go like aa, ab ac...az ... aaa,aab,aac....

Looks like i didnt express myself clearly enough at the beginning.

For mine? Try this:

For $i = 1 To 100
    ConsoleWrite(ToBase26($i) & @CRLF)
Next

Func ToBase26($i)
    Local $s = ""

    Do
        $s = Chr(Mod($i, 26) + 64) & $s
        $i = Int($i / 27)
    Until $i = 0

    Return StringReplace($s, "@", "Z")
EndFunc   ;==>ToBase26

It's not ideal, but it works.

A

B

C

D

E

F

G

H

I

J

K

L

M

N

O

P

Q

R

S

T

U

V

W

X

Y

Z

AA

AB

AC

AD

AE

AF

AG

AH

AI

AJ

AK

AL

AM

AN

AO

AP

AQ

AR

AS

AT

AU

AV

AW

AX

AY

AZ

AA

BB

BC

BD

BE

BF

BG

BH

BI

BJ

BK

BL

BM

BN

BO

BP

BQ

BR

BS

BT

BU

BV

BW

BX

BY

BZ

BA

BB

CC

CD

CE

CF

CG

CH

CI

CJ

CK

CL

CM

CN

CO

CP

CQ

CR

CS

CT

CU

CV

Edited by Mat

Share this post


Link to post
Share on other sites

ok now why 28 is BB and not AB? it should go like aa, ab ac...az ... aaa,aab,aac....

Looks like i didnt express myself clearly enough at the beginning.

Yep, I misunderstood you!

Sorry,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Mat your's code works nicely.

Just 1 question. what is mod()? and is it possible to do what mod() does with out mod() ? like using /*-+ instead?


edited

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Just 1 question. what is mod()? and is it possible to do what mod() does with out mod() ? like using /*-+ instead?

What part of the description in the helpfile for this function did you not understand? Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

I dont understand mod in general. it takes 2 args, but what it does with them? It's more math related question already.

But anyway, thanks for fast replies and what's most important for help.

Edited by E1M1

edited

Share this post


Link to post
Share on other sites

I dont understand mod in general. it takes 2 args, but what it does with them? It's more math related question already.

You didn't answer my question unless it means you didn't bother to read it because you thing it wont answer your question.

I think it does or at least gives you the keyword to research further.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

You simulate the behavior of Mod() quite easily. I wouldn't reccomend using these functions though. (untested, but they are likely to be allot slower than Mod().)

Func _NotMod($value1, $value2)
    Return $value1-($value2*Int($value1/$value2))
EndFunc

Func _NotMod2($value1, $value2)
    While $value1 >= $value2
        $value1 -= $value2
    WEnd
    Return $value1
EndFunc

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Think of your division when you were six. 9 divided by 4 is... 2 remainder 1. Mod returns the 1.

Mod(9, 4) = 1

In most languages it's '9 % 4 = 1' or something like that.

http://en.wikipedia.org/wiki/Modulo_operation

Not to be confused with moderators or people riding vespas.

Edited by Mat

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

I've read your question, and answered it. As I said I dont understand mod in general. There's no specific part in help file that i dont understand. If you want specific part, i would say Parameters.

Thanks Mat.

Edited by E1M1

edited

Share this post


Link to post
Share on other sites

I've read your question, and answered it. As I said I dont understand mod in general. There's no specific part in help file that i dont understand. If you want specific part, i would say Parameters.

geezzz... I am referring to the Mod() function in the helpfile , not the whole damn helpfile.

It is properly explained and I have sometimes the impression you take the easy way out and simply ask the question.

You are here long enough to sort these trivial things out yourself.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

If it's parameters then think like this:

a / b = c remainder d

Mod(a, B) = d

Edited by Mat

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

And I answered about mod. Maybe I wasn't clear. Instead of There's no specific part in help file that i dont understand. I should have said There's no specific part in mod() documentationthat I dont understand....I guess.

How should I express myself if I want to say you that I was reading mod function from help file and there wasn't any specific part in mod's documentation in help file that I didn't understand..

Edited by E1M1

edited

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0