|
-
Oct 26th, 2002, 02:39 PM
#1
Thread Starter
Frenzied Member
Convert Base 10 To 255
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.
-
Oct 26th, 2002, 03:06 PM
#2
PowerPoster
chr converts decimal to base 255 w/ ASCII representation
asc converts ASCII-represented base 255 to decimal equivalent
-
Oct 26th, 2002, 03:24 PM
#3
Lively Member
Remember back in algebra, when you learned how to solve proportions?
-
Oct 26th, 2002, 03:25 PM
#4
Thread Starter
Frenzied Member
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?
-
Nov 16th, 2002, 04:29 AM
#5
Thread Starter
Frenzied Member
Originally posted by FireSlash518
Remember back in algebra, when you learned how to solve proportions?
I got expelled this semester. I didnt get to learn about
proportions. Is there a thread in the maths section about this?
-
Nov 16th, 2002, 05:24 AM
#6
So Unbanned
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.
-
Nov 17th, 2002, 12:29 AM
#7
Thread Starter
Frenzied Member
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.
There are errors in your code and the first one does not
work...please help.
-
Nov 17th, 2002, 04:09 AM
#8
So Unbanned
Length = the number of characters to return.
You also need a Next.
num is the base 10 number.
-
Nov 17th, 2002, 04:11 AM
#9
Thread Starter
Frenzied Member
Originally posted by DiGiTaIErRoR
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 and
see how it works a bit better?
-
Nov 17th, 2002, 04:11 AM
#10
So Unbanned
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
-
Nov 17th, 2002, 04:13 AM
#11
So Unbanned
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.
-
Nov 17th, 2002, 04:16 AM
#12
Thread Starter
Frenzied Member
it dosent work on numbers above 256. I might as well just say
Chr(1-255)...
-
Nov 17th, 2002, 07:06 AM
#13
So Unbanned
richtextbox1.text = " " & b10to256(23084823,4)
-
Nov 20th, 2002, 04:54 AM
#14
Thread Starter
Frenzied Member
How do you find out what the "Character_Return" is?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|