Hey guys. I need 2 functions: one that will convert a base 10 to a
base 255. So all ASCII values would make the numbers. Get
where im at?
EDIT: And th eother function would convert base 255 to
base 10.
Printable View
Hey guys. I need 2 functions: one that will convert a base 10 to a
base 255. So all ASCII values would make the numbers. Get
where im at?
EDIT: And th eother function would convert base 255 to
base 10.
chr converts decimal to base 255 w/ ASCII representation
asc converts ASCII-represented base 255 to decimal equivalent
Remember back in algebra, when you learned how to solve proportions? ;)
Yes, but if i want to write 256 with this number system i would
have to go Chr(1) & Chr(1) then 257 would be CHr(1) & Chr(2)
etc etc...can you help me?
I got expelled this semester. I didnt get to learn aboutQuote:
Originally posted by FireSlash518
Remember back in algebra, when you learned how to solve proportions? ;)
proportions. Is there a thread in the maths section about this?
That'd be base 256, not 255.
But anyway....
to convert from base 10 to 256 you'll have to check the value you have, then get how many spaces that'll be in the new base.
VB Code:
'since i use this function with a number that I need a fixed length of it was written to produce a result with a fixed length, but you can change that. Then for x = length to 1 step -1 if num > (256 ^ x) then b256 = b256 & chr$(int(num/(256^x))) num = num - (int(num/(256^x))*(256^x)) else b256 = b256 & chr$(0) ' not greater, so it's 0 end if b256 = b256 & chr$(num)
doing 256 to 10 is fairly easy.
VB Code:
For x = Len(Base256Chrs) - 1 To 1 Step -1 i = i + 1 rt = rt + (Asc(Mid$(Base256Chrs, x, 1)) * (256 ^ i)) Next rt=rt + Asc(Right$(Base256Chrs, 1))
That'll do it.
There are errors in your code and the first one does notQuote:
Originally posted by DiGiTaIErRoR
That'd be base 256, not 255.
But anyway....
to convert from base 10 to 256 you'll have to check the value you have, then get how many spaces that'll be in the new base.
VB Code:
'since i use this function with a number that I need a fixed length of it was written to produce a result with a fixed length, but you can change that. Then for x = length to 1 step -1 if num > (256 ^ x) then b256 = b256 & chr$(int(num/(256^x))) num = num - (int(num/(256^x))*(256^x)) else b256 = b256 & chr$(0) ' not greater, so it's 0 end if b256 = b256 & chr$(num)
doing 256 to 10 is fairly easy.
VB Code:
For x = Len(Base256Chrs) - 1 To 1 Step -1 i = i + 1 rt = rt + (Asc(Mid$(Base256Chrs, x, 1)) * (256 ^ i)) Next rt=rt + Asc(Right$(Base256Chrs, 1))
That'll do it.
work...please help.
Length = the number of characters to return.
You also need a Next.
num is the base 10 number.
Can you post the function in it's entirety? So i can poke at it andQuote:
Originally posted by DiGiTaIErRoR
Length = the number of characters to return.
You also need a Next.
num is the base 10 number.
see how it works a bit better?
The whole thing:
VB Code:
Function B10To256(ByVal initval As Double, ByVal Character_Return As Integer) As String Dim rt As String Dim x As Long goal = initval DoEvents For x = Character_Return - 1 To 1 Step -1 If goal >= (256 ^ x) Then rt = rt & Chr$(Int(goal / (256 ^ x))) goal = goal - (Int(goal / (256 ^ x)) * (256 ^ x)) Else rt = rt & Chr$(0) End If Next rt = rt & Chr$(goal) B10To256 = rt End Function
Since base 256 is often helpful in hex, here's a function to flipbytes, thus flip the endian.
VB Code:
Function FlipBytes(ByVal ByteTF As String, Optional ByVal ByteWidth As Long) As String Dim x As Long Dim ns As String If ByteWidth < 1 Then ByteWidth = 1 If ByteWidth > 2 Then ByteWidth = 2 For x = 1 To Len(ByteTF) Step ByteWidth ns = Mid$(ByteTF, x, ByteWidth) & ns Next FlipBytes = ns End Function
Bytewidth refers to the base representation. For an ascii base 256, it'll be 1, for hex: 2, binary: 8.
This function now only works on hex and ascii.
it dosent work on numbers above 256. I might as well just say
Chr(1-255)... :(
richtextbox1.text = " " & b10to256(23084823,4)
How do you find out what the "Character_Return" is?