locked
Changing bytes to Kbytes / Mbyts / etc

    Question

  • I have a program that downloads a file from net and it shows progress in progress bar and in a text box.... the problem is...it shows the data in Bytes....i wanna know how can i convert it and make it show in all others

    like

    Kbytes

    Mbytes

    Gbytes

    TBytes ( well maybe not Tbytes ;p  ^^ )

    thx ahead.

     

     

     

     

    Wednesday, February 07, 2007 12:25 AM

Answers

  • well the first thing to realize is that a kilo byte is actually 2^10 bytes or 1024 bytes....

    Kb = 2^10 =1024b

    Mb= 2^20=1,048,576b

    Gb=2^30=1,073,741,824b

    Tb=2^40=1,099,511,627,776b

    Pb=2^50

     

    now from there it is simple division to figure out how many kilobytes or portions of Petrabytes that you have

    Wednesday, February 07, 2007 2:16 AM
  • Hi.

    The value that you are getting is correct. You just have to format it.

    Take a look at this example.

    Dim var1 As Double = 3560
            var1 = var1 / 1024
            MsgBox(FormatNumber(var1))

    Best regards.

    dp
    Wednesday, February 07, 2007 12:11 PM

All replies

  • well the first thing to realize is that a kilo byte is actually 2^10 bytes or 1024 bytes....

    Kb = 2^10 =1024b

    Mb= 2^20=1,048,576b

    Gb=2^30=1,073,741,824b

    Tb=2^40=1,099,511,627,776b

    Pb=2^50

     

    now from there it is simple division to figure out how many kilobytes or portions of Petrabytes that you have

    Wednesday, February 07, 2007 2:16 AM
  • Sorry but i didn't got it

     

     

    if you don't mine...this is my code that show the Bytes into a Label....can you edit it and show me how should i do it to change the Bytes into Kbytes / Mbytes / etc

     

     

     

    Label1.Text = e.BytesReceived.ToString() & " Bytes Out Of " & e.TotalBytesToReceive.ToString()

     

     

    Wednesday, February 07, 2007 10:53 AM
  • 8 bits = 1 Byte
    1024 Bytes = 1 Kbyte
    1024 Kbytes = 1 Mbyte
    1024 Mbytes = 1 Gigabyte
    1024 Gigabytes = 1 Terabyte

    This is plain math now...

    3265Kb = Mb?

    3265 / 1024 = 3,18Mb

    Did you get it now?

     

    Best regards.

    dp

    (www.webhostservices.biz)

    Wednesday, February 07, 2007 11:03 AM
  • not really :S...

    that's what i tryed

    Dim Prg1 As Double

    Prg1 = e.TotalBytesToReceive / 1024

    and i get a even bigger number:   xxxx.xxxxxxxx about |:

     

     

    Wednesday, February 07, 2007 11:32 AM
  • Hi.

    The value that you are getting is correct. You just have to format it.

    Take a look at this example.

    Dim var1 As Double = 3560
            var1 = var1 / 1024
            MsgBox(FormatNumber(var1))

    Best regards.

    dp
    Wednesday, February 07, 2007 12:11 PM
  •  

    Try this:

    Prg1 = e.TotalBytesToReceive >> 10

    Wednesday, February 07, 2007 12:17 PM
  •  ReneeC wrote:

     

    Try this:

    Prg1 = e.TotalBytesToReceive >> 10

     

    Honestly i don't know how a "right shift on a bit pattern" wil help on formating a decimal value.

    Best regards.

    dp

    (www.webhostservices.biz)

    Wednesday, February 07, 2007 12:42 PM