|
-
Aug 2nd, 2001, 04:11 AM
#1
Thread Starter
Lively Member
Converting bytes to kbytes.
Can you believe I can't figure it out? And can you believe that I've never had to do this before? =).
Anyway, what I need to do is convert an integer of a file's size from bytes to kbytes and mbytes etc.
So say something is 1024 bytes, I know that's a kbyte, but what process / math do I have to use to work it all the way up to terabytes without loosing integrity in the numbers.
Both to and from conversions would be useful.
Thanks in advance. =).
-
Aug 2nd, 2001, 04:20 AM
#2
1024btyes = 1kbyte
1024kbytes = 1mbyte
1024mbytes = 1gbyte
1024gbytes = 1tbyte
simple eh?
-
Aug 2nd, 2001, 04:24 AM
#3
Retired VBF Adm1nistrator
and
1 Exabyte = 1,152,921,504,606,846,976 Bytes
= 1125899906842624 KBytes
= 1099511627776 MBytes
= 1073741824 GBytes
= 1048576 TBytes
= 1024 PetaBytes
= 1 Exabyte
Zettabyte ~ 1 000 000 000 000 000 000 000 bytes
Yottabyte ~ 1 000 000 000 000 000 000 000 000 bytes
And the reasons for the names :
Kilo Greek khilioi = 1000
Mega Greek megas = great, e.g., Alexandros Megos
Giga Latin gigas = giant
Tera Greek teras = monster
Peta Greek pente = five, fifth prefix, peNta - N = peta
Exa Greek hex = six, sixth prefix, Hexa - H = exa
Remember, in standard French, the initial H is silent, so they would pronounce Hexa as Exa.
Zetta almost homonymic with Greek Zeta, but last letter of the Latin alphabet
Yotta almost homonymic with Greek iota, but penultimate letter of the Latin alphabet.
Last edited by plenderj; Aug 2nd, 2001 at 04:32 AM.
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Aug 2nd, 2001, 04:26 AM
#4
-= B u g S l a y e r =-
VB Code:
Option Explicit
Public Enum convTo
KB = 1
MB = 2
GB = 3
TB = 4
End Enum
Public Function BytesTO(lBytes As Long, convertto As convTo) As Double
BytesTO = lBytes / (1024 ^ convertto)
End Function
Private Sub Command1_Click()
MsgBox BytesTO(2048, KB)
End Sub
not sure abot this
-
Aug 2nd, 2001, 04:27 AM
#5
1024btyes = 1kbyte
1024kbytes = 1mbyte
1024mbytes = 1gbyte
1024gbytes = 1tbyte
simple eh? 
1mbytes = 1048576bytes
1gbyte = 1,073,741,824bytes
1tbyte = 1,099,511,627,776bytes
-
Aug 2nd, 2001, 04:32 AM
#6
Originally posted by peet
VB Code:
Option Explicit
Public Enum convTo
KB = 1
MB = 2
GB = 3
TB = 4
End Enum
Public Function BytesTO(lBytes As Long, convertto As convTo) As Double
BytesTO = lBytes / (1024 ^ convertto)
End Function
Private Sub Command1_Click()
MsgBox BytesTO(2048, KB)
End Sub
not sure abot this
Option Explicit
Public Enum convTo
KB = 1
MB = 2
GB = 3
TB = 4
End Enum
Public Function BytesTO(lBytes As Double, convertto As convTo) As Double
BytesTO = lBytes / (1024 ^ convertto)
End Function
Private Sub Command1_Click()
MsgBox BytesTO(1099511627776#, TB)
End Sub
Changed to As Double as there is a over flow on the 1TB, but it works.
-
Aug 2nd, 2001, 04:35 AM
#7
-
Aug 2nd, 2001, 04:37 AM
#8
Migth also want to try lBytes As Currency to get large numbers
-
Aug 3rd, 2001, 12:33 AM
#9
Thread Starter
Lively Member
Thanks for all the help. =).
But I'm trying to do this in vbscript. If anyone knows another way to do it please reply.
Thanks.
-
Aug 3rd, 2001, 02:14 AM
#10
Retired VBF Adm1nistrator
Peet's code should do it.
Just dont declare the varibles as a specific type, and dont declare parameters as being a specific type either ;
VB Code:
Dim KB
Dim MB
Dim GB
Dim TB
KB = 1
MB = 2
GB = 3
TB = 4
Function BytesTO(lBytes, convertto)
BytesTO = lBytes / (1024 ^ convertto)
End Function
Sub Command1_Click()
MsgBox BytesTO(2048, KB)
End Sub
That *should* work.
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Aug 3rd, 2001, 03:51 AM
#11
You would use Constants instead
VB Code:
Const KB = 1
Const MB = 2
Const GB = 3
Const TB = 4
Function BytesTO(lBytes, convertto)
BytesTO = lBytes / (1024 ^ convertto)
End Function
Response.Write(BytesTO(2048, KB))
-
Aug 3rd, 2001, 03:56 AM
#12
Retired VBF Adm1nistrator
I didnt think VBScript would support the Const keyword ... oh well, ya learn something new every day
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Aug 3rd, 2001, 03:58 AM
#13
Fanatic Member
Easy in C
MB = kB >> 10
-
Aug 3rd, 2001, 04:01 AM
#14
-
Aug 3rd, 2001, 04:08 AM
#15
-
Aug 3rd, 2001, 04:16 AM
#16
Retired VBF Adm1nistrator
Ah just hurry up and buy SBS2000 and then bugger off
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Aug 3rd, 2001, 04:25 AM
#17
hehe, Patience, Patience my son... you dont expect me to pay a few K in a day eh?
-
Aug 3rd, 2001, 04:32 AM
#18
Retired VBF Adm1nistrator
My other customers do
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Aug 3rd, 2001, 04:51 AM
#19
well so, we arnt in need of this, and it aint on our priorities yet
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
|