Page 1 of 2 12 LastLast
Results 1 to 40 of 46

Thread: [2005] convet sting to integer in the same format

  1. #1

    Thread Starter
    Fanatic Member karthikeyan's Avatar
    Join Date
    Oct 2005
    Location
    inside .net
    Posts
    919

    [2005] convet sting to integer in the same format

    dear friend,

    i need to convert the following string in to integer.

    "002"

    i need to convert to integer then my ineger should be as follows;
    002

    i have tried using CInt. but it gives 2.so how can i convert this to get integer as 002.
    Loving dotnet

  2. #2
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    Re: [2005] convet sting to integer in the same format

    002 isn't an integer or any kind of number. If you want to keep the zeroes in front, you need to keep it as a string. Leading zeroes mean nothing in a number.

  3. #3
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] convet sting to integer in the same format

    As Tom said, you can't.

    One thing which you might want to do is keep the leading 0's for display purposes and i've found that pad left etc... is good for this.

    (Just as a quick example)
    vb Code:
    1. Dim myStr1 As String = "002"
    2. Dim myStr2 As String = "005"
    3.  
    4. Dim total As Integer = CInt(myStr1) + CInt(myStr2)
    5.  
    6. MessageBox.Show(total.ToString.PadLeft(3, "0"))
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  4. #4

    Thread Starter
    Fanatic Member karthikeyan's Avatar
    Join Date
    Oct 2005
    Location
    inside .net
    Posts
    919

    Re: [2005] convet sting to integer in the same format

    dear friends

    thanks for the reply.
    Loving dotnet

  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] convet sting to integer in the same format

    Quote Originally Posted by Tom Sawyer
    002 isn't an integer or any kind of number. If you want to keep the zeroes in front, you need to keep it as a string. Leading zeroes mean nothing in a number.

    002 is by all means a number and an integer. VB (any programming language for that matter) just does not hold on to non significant digits in numeric data types.

    002 isn't an integer = false

  6. #6
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    Re: [2005] convet sting to integer in the same format

    Quote Originally Posted by kleinma
    002 is by all means a number and an integer. VB (any programming language for that matter) just does not hold on to non significant digits in numeric data types.

    002 isn't an integer = false
    No, 002 is a string. 2 is an integer. When any language reads 002 as an integer, it strips off the zeros and reads it as 2.

  7. #7
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] convet sting to integer in the same format

    no

    "002" is a string

    002 is an integer

    Go find a mathematician, and tell them 002 is not an integer value

  8. #8
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    Re: [2005] convet sting to integer in the same format

    Quote Originally Posted by kleinma
    no

    "002" is a string

    002 is an integer

    Go find a mathematician, and tell them 002 is not an integer value
    We're talking about programming, not theoretical mathematics.

    Go into Visual Studio. Type:

    Dim x as integer

    x = 002

    Then press enter and see what happens. Go find a programmer who will have anything else happen.

  9. #9
    Addicted Member
    Join Date
    Mar 2007
    Location
    San Pedro de Macoris, Dominican Republic
    Posts
    211

    Re: [2005] convet sting to integer in the same format

    I guess for the purposes of programming languajes it's pointless to wheter or not 002 is an integer or string. Such discussion doesn't serve the purpose of the thread I would guess.

  10. #10
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] convet sting to integer in the same format

    Quote Originally Posted by Tom Sawyer
    002 isn't an integer or any kind of number.
    Tom you said 002 is not an integer or any kind of number.

    Yes I know VB strips insignificant digits from numbers. That is very true. That however does NOT mean 002 is not a number. You called it a string..

    However which line of code is going to give you an error?
    Code:
    Dim myInt as Integer = 002
    Dim myString as String = 002
    Sorry.. we could fight over it I suppose, but what is the point?

    I know the message you were trying to convey to the OP, and I think you answered his question to his liking, I am just correcting what was incorrectly stated in your post.

  11. #11
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    Re: [2005] convet sting to integer in the same format

    Dim myInt as Integer = 002 becomes
    Dim myInt as Integer = 2 as soon as I press enter.

    What mathematicians call a number is not relevant. What the CLR interprets a System.Int32 value as is what matters, as that is the definition of an integer in visual basic. Leading zeros are not included in this interpretation, so if you want to have something with leading zeros, you cannot use this value type to store it on the stack. For the definition of a Visual Basic Integer, that's all that matters.

  12. #12
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2005] convet sting to integer in the same format

    Quote Originally Posted by kleinma
    no

    "002" is a string

    002 is an integer

    Go find a mathematician, and tell them 002 is not an integer value
    This is correct. I cant see why you would want to keep the leading zeros in any calculations but for displaying its just a formatting issue.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  13. #13
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] convet sting to integer in the same format

    Quote Originally Posted by Tom Sawyer
    Dim myInt as Integer = 002 becomes
    Dim myInt as Integer = 2 as soon as I press enter.

    What mathematicians call a number is not relevant. What the CLR interprets a System.Int32 value as is what matters, as that is the definition of an integer in visual basic. Leading zeros are not included in this interpretation, so if you want to have something with leading zeros, you cannot use this value type to store it on the stack. For the definition of a Visual Basic Integer, that's all that matters.
    it doesn't store them because they make no difference in the math that will be done with them. It would just be wasted 0s taking up space in memory.

    Just because the IDE happens to be productive and strips insignificant digits when you use them, still does not mean 002 is not a number.

    If I code in notepad, and compile against the VBC I could write

    Dim myInteger as integer = 002

    Notepad sure isn't going to strip those 0s for me. The compiler will, but I will never see that happen.

    I am not trying to fight you on what the IDE or VB language does to leading 0s. I am just saying your claim that 002 is not a number simply is not correct. If you don't want to agree with that, then that is your decision.

  14. #14
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] convet sting to integer in the same format

    Crikey, I go away for 15 minutes and this simple little post has turned mental.

    Tom,
    Kleinma was only pointing out that your blanket sounding statement ("002 isn't any kind of number") wasn't accurate and is fair enough.

    It's just a matter of scope really. You are saying when you press return the 0's won't stay there within the IDE which is fair enough. But that's not the same as saying 002 isn't a numerical type (inside or outside of any IDE) which is what your statement sort of implied.

    I don't want to get caught in any cross fire here, so I'm waving my white flag and running away but i know exactly what has caused this and as Kleinma has said - it's not worth any more time.

    *runs and ducks for cover*
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  15. #15
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    Re: [2005] convet sting to integer in the same format

    Quote Originally Posted by kleinma

    I am not trying to fight you on what the IDE or VB language does to leading 0s. I am just saying your claim that 002 is not a number simply is not correct. If you don't want to agree with that, then that is your decision.
    It isn't a number. By number, I of course mean a numeric value type that the CLR can read. Which one of those allocates memory on the stack for a value that contains leading zeros? If there isn't one, then 002 is not a number inside of VB or any other .NET language.

    This is a programming forum, so the programmatic definition of a number is the only one that matters. The IDE's functionality, while indictive of what happens on a lower level, is not the core issue. The core issue is what gets compiled to the IL and the CLR. A mathematician's definition of an integer is as relative to the discussion as it would be if there's some cook who calls a pound of flour an integer - it just doesn't matter as relates to a VB program.

    Inside VB, 002 is not a number.

  16. #16
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] convet sting to integer in the same format

    Like I said, there is no point in arguing this further. You keep your opinion, and I will keep mine.

    Maybe someday you will go for some programming job and they will ask you what 002 is. Go ahead and tell them its not a number, its a string.

  17. #17
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    Re: [2005] convet sting to integer in the same format

    Quote Originally Posted by kleinma
    Like I said, there is no point in arguing this further. You keep your opinion, and I will keep mine.

    Maybe someday you will go for some programming job and they will ask you what 002 is. Go ahead and tell them its not a number, its a string.
    It's not an opinion, it's a fact. There is no System.Int32 value of 002.

    Maybe someday, you will have a programming job where you will be asked to store leading zeros in a numeric data type. Good luck with that.

  18. #18
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] convet sting to integer in the same format

    002 = 2 = 00000000000000000000000000000000002

    insignificant digits (leading 0s) is concept.... they all equal values..

    The statement you made, that prompted my comment, was when you said 002 is "NOT ANY KIND OF NUMBER". To that I said you are wrong, 002 is very much a number.

    I never say you could store insignificant digits in numeric data types, all I said was 002 is a number. You called it a string.

    It is a fact that you can not store insigificant digits in numeric data types, it is NOT a fact that 002 is not a number, and it is very much not a string...

  19. #19
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    Re: [2005] convet sting to integer in the same format

    It doesn't matter what it is as a concept, it matters what it is as a value on the stack. A System.Int32 value type does not store a value of 002 or 0000000002 or any other number of leading zeros and a 2. It only stores the 2. Therefore, inside of visual basic, there is no integer with a value of 002.

    The fact that outside of visual basic, there are things called integers that can have a value of 002 is not relevant to the fact that there is nothing inside of it that can have that value.

  20. #20
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] convet sting to integer in the same format

    but numbers exist outside visual basic, and you said 002 is not a number.

    Am I taking you too literally? Maybe... but my point in posting was just to correct that generalized statement you made, because just because YOU know how VB/CLR treats numbers, and I know as well, doesn't mean a few million others who might come across this thread know.

    So to make a statement like 002 is not a number, versus saying something like System.Int32 can not represent insignificant digits, I felt compelled to post and say I don't agree with the statement.

  21. #21
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: [2005] convet sting to integer in the same format

    Actually you are all wrong. I am willing to bet that the system will store you integer 2 or 002 or 0000000002 as:

    0x00000002

    And int64 on a 64 bit operating system:

    0x0000000000000002

    Mathematically speaking 002 is an integer. If you want to display 002 in your program it needs to be converted to a string otherwise only significant figures will be displayed; therefore in programming speak you cannot store the number of leading zeros unless you store it as string so 002 can only be represented literally with a string. If you want to store 002 then store it as an int or a long or a byte.

    Why the pointless argument?
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  22. #22
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] convet sting to integer in the same format

    To avoid VS interference, I created a .vb file

    Code:
    Module Main
        Sub Main()
            Dim i as Int32 = 002
    	Console.WriteLine(i.GetType().Name)	
        End Sub
    End Module
    (notepad)

    And then ran vbc.exe against it.

    vbc test.vb

    The .exe generated gave this output:

    Int32

    That means that 002 is a number, although the leading 0s may be removed at runtime.

  23. #23
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: [2005] convet sting to integer in the same format

    I am willing to argue in favour for the addition of this new sting data type
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  24. #24
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    Re: [2005] convet sting to integer in the same format

    Quote Originally Posted by kleinma
    but numbers exist outside visual basic, and you said 002 is not a number.

    Am I taking you too literally? Maybe... but my point in posting was just to correct that generalized statement you made, because just because YOU know how VB/CLR treats numbers, and I know as well, doesn't mean a few million others who might come across this thread know.

    So to make a statement like 002 is not a number, versus saying something like System.Int32 can not represent insignificant digits, I felt compelled to post and say I don't agree with the statement.
    If someone asks how to do something in a loop, do you tell him how to do it while he's driving on a roundabout, or do you understand that, due to the forum he's posting in, he's referring to the programmatic definition of a loop and not some other definition of the word? Why would it be different for an integer?

    Integer means System.Int32. They're synonyms. Number means numeric datatype. It doesn't refer to a song someone is playing or any other definition of the word that isn't referring to a programming concept.

  25. #25
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] convet sting to integer in the same format

    Sorry, forgot the ILDASM output

    Code:
    .method public static void  Main() cil managed
    {
      .entrypoint
      .custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = ( 01 00 00 00 ) 
      // Code size       24 (0x18)
      .maxstack  1
      .locals init (int32 V_0)
      IL_0000:  ldc.i4.2
      IL_0001:  stloc.0
      IL_0002:  ldloc.0
      IL_0003:  box        [mscorlib]System.Int32
      IL_0008:  callvirt   instance class [mscorlib]System.Type [mscorlib]System.Object::GetType()
      IL_000d:  callvirt   instance string [mscorlib]System.Reflection.MemberInfo::get_Name()
      IL_0012:  call       void [mscorlib]System.Console::WriteLine(string)
      IL_0017:  ret
    } // end of method Main::Main
    Hope that doesn't help in any constructive way at all.

  26. #26
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] convet sting to integer in the same format

    Quote Originally Posted by visualAd
    Actually you are all wrong. I am willing to bet that the system will store you integer 2 or 002 or 0000000002 as:

    0x00000002

    And int64 on a 64 bit operating system:

    0x0000000000000002
    So what you are saying then, is if you assign a number to an integer type in VB, and that number does not fill up all the bytes of that data type, then what fills those leading spaces in memory??? 0s????

  27. #27
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    Re: [2005] convet sting to integer in the same format

    Actually, it helps immensely:

    IL_0003: box [mscorlib]System.Int32

    An extra line of processing is required to convert the value you typed in into an Int32. This is all I'm saying.

    Also, how come your IDE lets you put i = 002? Mine changes it to a 2.

  28. #28
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] convet sting to integer in the same format

    because his IDE is notepad...

  29. #29
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [2005] convet sting to integer in the same format

    I am almost 100% certain that 2

    as int32 looks like this in memory
    00000000000000000000000000000010

    and as Int64 like this in memory
    0000000000000000000000000000000000000000000000000000000000000010

    As custom we write numbers without leading zero's, but it is just a custom. No mathmatical rule or formula that I am aware of would break down if we chose not to observe the custom.
    1 + 1 = 2
    0001 + 0001 = 0002
    Last edited by dbasnett; Mar 5th, 2008 at 03:11 PM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  30. #30
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    Re: [2005] convet sting to integer in the same format

    Quote Originally Posted by kleinma
    because his IDE is notepad...
    Notepad isn't an IDE. IDE means Integrated Development Environment. Notepad is simply a text editor and this definition doesn't apply to it.

  31. #31
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] convet sting to integer in the same format

    No, no, let me explain. In order to avoid the IDE formatting the 002 in the first place, I created the console app in notepad and then compiled it with vbc.exe to see how the compiler would handle it.

  32. #32
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    Re: [2005] convet sting to integer in the same format

    Quote Originally Posted by mendhak
    No, no, let me explain. In order to avoid the IDE formatting the 002 in the first place, I created the console app in notepad and then compiled it with vbc.exe to see how the compiler would handle it.
    That's pretty f-ing clever. Good solution.

  33. #33
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] convet sting to integer in the same format

    Quote Originally Posted by Tom Sawyer
    That's pretty f-ing clever. Good solution.
    cough see post #13 cough

  34. #34
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    Re: [2005] convet sting to integer in the same format

    Quote Originally Posted by kleinma
    cough see post #13 cough
    Very well. You're clever too. I didn't see that part.

  35. #35
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [2005] convet sting to integer in the same format

    I can think of a custom where leading zero's are used, military time(see below). The below list has two errors though.

    12:00 AM -- 0000 hrs
    1:00 AM -- 0100 hrs
    2:00 AM -- 0200 hrs
    3:00 AM -- 0300 hrs
    4:00 AM -- 0400 hrs
    5:00 AM -- 0500 hrs
    6:00 AM -- 0600 hrs
    7:00 AM -- 0700 hrs
    8:00 AM -- 0800 hrs
    9:00 AM -- 0900 hrs
    10:00 AM -- 1000 hrs
    11:00 AM -- 1100 hrs
    12:00 PM -- 1200 hrs
    1:00 PM -- 1300 hrs
    2:00 PM -- 1400 hrs
    3:00 PM -- 1500 hrs
    4:00 PM -- 1600 hrs
    5:00 PM -- 1700 hrs
    6:00 PM -- 1800 hrs
    7:00 PM -- 1900 hrs
    8:00 PM -- 2000 hrs
    9:00 PM -- 2100 hrs
    10:00 PM -- 2200 hrs
    11:00 PM -- 2300 hrs
    Last edited by dbasnett; Mar 5th, 2008 at 03:33 PM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  36. #36
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] convet sting to integer in the same format

    Let's just agree that we're all clever and I'm 002 times as clever as both of you.

    I also have a feeling that this debate will be revisited in a few months time, these things don't go away.

  37. #37
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: [2005] convet sting to integer in the same format

    002 as in little endian or big endian?
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  38. #38
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: [2005] convet sting to integer in the same format

    First, this thread should be in more general forum. Why just in Visual Basic.NET. Share it with everyone.

    Second, this is my opinion, you may agree or not:

    In mathematics: "two always equals two", otherwise "two" does not belong to a numeric/counting system. That is the uniqeness of every number in a numeric system.

    In a computer system: "two may not equal two".
    "Byte" number two is stored by 8 bits as 00000010
    "Integer" number two is stored by 16 bits as 0000000000000010
    "Long" number two is stored by 32 bits as 00000000000000000000000000000010
    (You know how to write down "Int64" number two and so on)
    So, actually this "two" does not equal the other "two".

    "2" is the visual represent of number "two" by mean of an Arabic numeric system. Yes, that is Arabic.
    For a long time the western world use Rome's sytem: I II III IV V VI ... and in this sytem "II" represents number "two".
    The Chinese people use "二" to represent number "two".

    The Arabic numeric system originally did not have number "0". To make it becomes a complete numeric system (when doing subtraction a-b with a=b leading to the creation of 0), that "0" was added in not long ago, just 4-5 centuries and that "0" came from India in an original form of a small dot (·).[*]
    (open this thread of our forum too view the discussion on the problem of missing "ZERO" in a counting system, that is used to denote columns in Excel)

    Under Arabic numeric system (with 0), traditionally on writting a number, all leading 0's are dropped, because 2 = 02 = 002 = 0002 = 0...02. That is an axiom of this system.

    So, by mean of a mathematics numeric system, 002 and 2 are two of infinite ways to present the number "two".
    And 002 is really a number in this system.

    Added: If you want a computer system display number "two" as 002 instead of 2, just ask Bill Gates, may be he can do it.
    Added again: Have you ever seen a banking accouting report that comes straight from Cobol output? Most of numbers come with leading 0's.
    [*] Correction: I mixed up between 0 (·) and decimal-dot (.). That was corrected as blue text above.
    Last edited by anhn; Mar 6th, 2008 at 06:22 AM.
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  39. #39
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: [2005] convet sting to integer in the same format

    Quote Originally Posted by mendhak
    No, no, let me explain. In order to avoid the IDE formatting the 002 in the first place, I created the console app in notepad and then compiled it with vbc.exe to see how the compiler would handle it.
    Your test was crippled by the fact that you told the compiler explicitly what you demanded the number should be cast to eg...
    Code:
    Dim i as Int32 = 002
    So it really doesn't prove much of anything apart from the fact that your compiler works
    I don't live here any more.

  40. #40
    Hyperactive Member
    Join Date
    Mar 2001
    Location
    Calgary, Canada
    Posts
    453

    Re: [2005] convet sting to integer in the same format

    Pfaff! What's all this decimal tish tosh anyway?

    I just entered

    int a = 0x002;

    in to my C# ide and it took it (where 0x is the denominator for hexadecimal). I think in vb it's

    a = &H002

    So in Hex, 002 is definetly a valid number. Next thing you'll be telling me is that A isn't a valid number!
    "I'd rather have a full bottle in front of me than a full frontal lobotomy!"

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width