Page 1 of 2 12 LastLast
Results 1 to 25 of 44

Thread: ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User cecko19's Avatar
    Join Date: Jan:2011
    Location: Sofia
    Posts: 82

    ?

    !
    1-2 , 2-3 , .
    ( ) . - .
    C# , ...
    .
    Code:
    using System;
    using System.Numerics;
    using System.Text;
    using Extension.String.Reverse;
    
    namespace BinaryConverter
    {
        class BinaryConverter
        {
            static int HornerScheme(int convertionSystem, string numberForConvert)
            {
                int converted = 0;
    
                if (convertionSystem < 10)
                {
                    converted = (int)numberForConvert[0] - 48;
    
                    for (int i = 1; i < numberForConvert.Length; i++)
                    {
                        converted = convertionSystem * converted + (int)numberForConvert[i] - 48;
                    }
                }
    
                else if (convertionSystem > 10)
                {
                    if ((int)numberForConvert[0] > 64)
                    {
                        converted = (int)numberForConvert[0] - 55;
                    }
    
                    else converted = (int)numberForConvert[0] - 48;
    
                    for (int i = 1; i < numberForConvert.Length; i++)
                    {
                        if ((int)numberForConvert[i] > 64)
                        {
                            converted = convertionSystem * converted + (int)numberForConvert[i] - 55;
                        }
    
                        else
                        {
                            converted = convertionSystem * converted + (int)numberForConvert[i] - 48;
                        }
                    }
                }
    
                return converted;
            }
    
            static int FromAnyToDecimal(string numberToConvert)
            {
                Console.WriteLine("Input the system in which the number is.");
                int numberConvertionSystem;
                bool isCorrect = int.TryParse(Console.ReadLine(), out numberConvertionSystem);
                if (!isCorrect)
                {
                    throw new FormatException("The system is not in a valid format.");
                }
    
                return HornerScheme(numberConvertionSystem, numberToConvert);
            }
    
            static StringBuilder ConvertToAny(int convertionSystem, BigInteger numberForConvert)
            {
                StringBuilder convertedNumber = new StringBuilder();
                do
                {
                    if (numberForConvert % convertionSystem > 9)
                    {
                        convertedNumber.Append((char)(numberForConvert % convertionSystem + 55));
                    }
    
                    else
                    {
                        convertedNumber.Append(numberForConvert % convertionSystem);
                    }
    
                    numberForConvert /= convertionSystem;
                }
                while (numberForConvert >= convertionSystem);
    
                if (numberForConvert > 9 && numberForConvert != 0)
                {
                    convertedNumber.Append((char)(numberForConvert + 55));
                }
    
                else if (numberForConvert <= 9 && numberForConvert != 0)
                {
                    convertedNumber.Append(numberForConvert);
                }
    
                return convertedNumber.Reversed();
            }
    
            static StringBuilder FromDecimalToAny(BigInteger numberToConvert)
            {
                Console.WriteLine("Input the system to which you want to convert.");
                int numberConvertionSystem;
                bool isCorrect = int.TryParse(Console.ReadLine(), out numberConvertionSystem);
                if (!isCorrect)
                {
                    throw new FormatException("The system is not in a valid format.");
                }
    
                return ConvertToAny(numberConvertionSystem, numberToConvert);
            }
    
            static void Main(string[] args)
            {
                Console.WriteLine("Input the number you want to convert.");
                BigInteger number;
                bool isCorrect = BigInteger.TryParse(Console.ReadLine(), out number);
                if (!isCorrect)
                {
                    throw new ArgumentException("The value of the number is string.");
                }
    
                Console.WriteLine(
                    "Do you want to convert the number from any system to decimal or the opposite?" + 
                    "\nType any for the first option or other for the second option.");
                string answer = Console.ReadLine();
                
                switch (answer)
                {
                    case "any": Console.WriteLine(FromAnyToDecimal(number.ToString())); break;
                    case "other": Console.WriteLine(FromDecimalToAny(number)); break;
                    default: throw new ArgumentException("The answer is not valid.");
                }
            }       
        }
    }
    Extension StringBuilder-
    Code:
    using System.Text;
    
    namespace Extension.String.Reverse
    {
        public static class ExtensionStringReverse
        {
            public static StringBuilder Reversed(this StringBuilder str)
            {
                StringBuilder reversedWord = new StringBuilder();
                for (int i = str.Length - 1; i >= 0; i--)
                {
                    reversedWord.Append(str[i]);
                }
    
                return reversedWord;
            }
        }
    }
    !!!

  2. #2
    Teh AimeR AimeR's Avatar
    Join Date: Dec:2006
    Location: //
    Posts: 4,307
    16 . , .

    (), . , , , -, .

    , - , - , , :
    -
    -
    - , .. :
    Code:
     if (...)
                {
                   ....
                }
    
                else  if (...)
                {
                   ....
    
                    for (...)
                    {
                         if (...)
                        {
                            .....
                        }
    
                        else
                        {
           ?
                        }
    ASUS X570-P|R7 5800X3D@NH-U14S|2X16G DDR4 3200 Corsair VENGEANCE LPX|Samsung 980 PRO 1TB|Radeon RX 7900 XTX 24G|AOC CQ32G1|Corsair RM750x|CM 693

  3. #3
    Registered User cecko19's Avatar
    Join Date: Jan:2011
    Location: Sofia
    Posts: 82
    "" , , , ( ).

    !

  4. #4
    Nuclear's Avatar
    Join Date: Sep:2004
    Location: , . ()
    Posts: 3,352
    .
    :
    statement if-, .
    ., :

    Code:
    if (numberForConvert % convertionSystem > 9)
                    {
                        convertedNumber.Append((char)(numberForConvert % convertionSystem + 55));
                    }
    :
    Code:
    if (numberForConvert % convertionSystem > 9) convertedNumber.Append((char)(numberForConvert % convertionSystem + 55));
    . HWBG !

  5. #5
    Registered User cecko19's Avatar
    Join Date: Jan:2011
    Location: Sofia
    Posts: 82
    , - .

  6. #6
    Bombera's Avatar
    Join Date: Jul:2001
    Location: 4EVA
    Posts: 13,833
    , , . :
    Code:
    void * _nowhere(){
        return NULL;
    }
    EVGA X299 FTW K|i9-7960X@4.7|4x8 Patriot Viper Steel 4000|GTX 1660 Ti|970 EVO 1 TB|Seasonic Focus GX-1000|Xigmatek Elysium|
    Rampage IV Extreme BE|E5-1680v2@4.7|4x4 HyperX 1866|Cougar Aqua 240|GTX 1050 Ti|970 EVO 1/4 TB|CM 850 SilentPro|HAF-X|

  7. #7
    Registered User cecko19's Avatar
    Join Date: Jan:2011
    Location: Sofia
    Posts: 82
    . - . - , .

    !

  8. #8
    Teh AimeR AimeR's Avatar
    Join Date: Dec:2006
    Location: //
    Posts: 4,307
    ( ).

    , , - .

    :
    Quote Originally Posted by Bombera View Post
    ...
    Code:
    void * _nowhere(){
        return NULL;
    }
    , - if- !

    , , ... auto-format , .
    ASUS X570-P|R7 5800X3D@NH-U14S|2X16G DDR4 3200 Corsair VENGEANCE LPX|Samsung 980 PRO 1TB|Radeon RX 7900 XTX 24G|AOC CQ32G1|Corsair RM750x|CM 693

  9. #9
    Bombera's Avatar
    Join Date: Jul:2001
    Location: 4EVA
    Posts: 13,833
    Quote Originally Posted by AimeR View Post
    ...


    @bsb
    , , " ..."
    , , , .
    EVGA X299 FTW K|i9-7960X@4.7|4x8 Patriot Viper Steel 4000|GTX 1660 Ti|970 EVO 1 TB|Seasonic Focus GX-1000|Xigmatek Elysium|
    Rampage IV Extreme BE|E5-1680v2@4.7|4x4 HyperX 1866|Cougar Aqua 240|GTX 1050 Ti|970 EVO 1/4 TB|CM 850 SilentPro|HAF-X|

  10. #10
    Registered User cecko19's Avatar
    Join Date: Jan:2011
    Location: Sofia
    Posts: 82
    , ...

    - unit .

    ,

  11. #11
    Bombera's Avatar
    Join Date: Jul:2001
    Location: 4EVA
    Posts: 13,833
    19001200 8 ,
    EVGA X299 FTW K|i9-7960X@4.7|4x8 Patriot Viper Steel 4000|GTX 1660 Ti|970 EVO 1 TB|Seasonic Focus GX-1000|Xigmatek Elysium|
    Rampage IV Extreme BE|E5-1680v2@4.7|4x4 HyperX 1866|Cougar Aqua 240|GTX 1050 Ti|970 EVO 1/4 TB|CM 850 SilentPro|HAF-X|

  12. #12
    Registered User cecko19's Avatar
    Join Date: Jan:2011
    Location: Sofia
    Posts: 82

  13. #13
    Registered User
    Join Date: Oct:2003
    Location:
    Posts: 4,317
    ,
    Quote Originally Posted by cecko19 View Post
    ..... ( ).....
    , "BinaryConverter"?
    magic numbers - 48, 64, 55. , , 48 ASCII 0, 64 @, 55 65-10. .
    , ?

    Quote Originally Posted by Nuclear
    .....
    :
    statement if-, .
    . if- . , , , .

    Quote Originally Posted by Bombera
    , , .
    , flame wars, , (top posting - bottom posting) -, vi emacs.

  14. #14
    Registered User cecko19's Avatar
    Join Date: Jan:2011
    Location: Sofia
    Posts: 82
    !

    , .
    BinaryConverter, . . .
    , .

    ""

    bsb

  15. #15
    Registered User
    Join Date: Jul:2004
    Location:
    Posts: 621
    . :

    1) "" 48, 64 (65) .. - . , , , :
    Code:
                    //   /++ 
                    if (numberForConvert[0] >= '')
                    {
                        converted = 10 + numberForConvert[0] - '';
                    }
    
                    else converted = numberForConvert[0] - '0';
    2) static int HornerScheme() convertionSystem == 10

    3) , "int converted = 0;" , :
    Code:
              if (convertionSystem < 10)
                {
                    for (int i = 0; i < numberForConvert.Length; i++)
                    {
                        converted = convertionSystem * converted + (int)numberForConvert[i] - 48;
                    }
                }
    (i == 0) 1-2 , - -

  16. #16
    Registered User tedych's Avatar
    Join Date: Nov:2003
    Location:
    Posts: 17,654
    .
    , . . , , , - .
    flame wars , - . 0.0001% , .
    " " .. .. 2 1 , 1/3 , , DPI etc., , 19- 2 150% DPI, 14, .

    , . , , . , , , , IDE , , { } , - .

    ( ) , , , . 4-5 , - .

  17. #17
    Bombera's Avatar
    Join Date: Jul:2001
    Location: 4EVA
    Posts: 13,833
    /. C() , -, . / . , , "" , , , , .
    EVGA X299 FTW K|i9-7960X@4.7|4x8 Patriot Viper Steel 4000|GTX 1660 Ti|970 EVO 1 TB|Seasonic Focus GX-1000|Xigmatek Elysium|
    Rampage IV Extreme BE|E5-1680v2@4.7|4x4 HyperX 1866|Cougar Aqua 240|GTX 1050 Ti|970 EVO 1/4 TB|CM 850 SilentPro|HAF-X|

  18. #18
    hmm BornToDrink's Avatar
    Join Date: Aug:2005
    Location: .
    Posts: 11,573
    .
    - .

    :
    Code:
    if ($var)
        echo $var;
    50% IF- .

    ps - , , :
    Code:
    if (var>=5)
        var=(var2)?3:2;
    //     
    var=func(a,b,c);
    Hey, mother, I come bearing a gift. I'll give you a hint. It's in my diaper and it's not a toaster.
    .

  19. #19
    XaMaB's Avatar
    Join Date: Nov:2001
    Location:
    Posts: 20,387
    , . , , , , ..
    : XaMaB; . 0.42

    In God we Trust (all others must submit a X.509 certificate). , ()

  20. #20
    Registered User
    Join Date: Aug:2006
    Location:
    Posts: 4,052
    auto-formater. ,

  21. #21
    Nuclear's Avatar
    Join Date: Sep:2004
    Location: , . ()
    Posts: 3,352
    , , , / .

    ( java, , ). , statement, , . , - , .

    , . -, .
    . HWBG !

  22. #22
    Registered User
    Join Date: Aug:2006
    Location:
    Posts: 4,052
    Quote Originally Posted by Nuclear View Post
    , . -, .
    _

    Quote Originally Posted by Captain Hindsight
    , - , -,

  23. #23
    Registered User cecko19's Avatar
    Join Date: Jan:2011
    Location: Sofia
    Posts: 82
    , ...
    .

  24. #24
    Registered User tedych's Avatar
    Join Date: Nov:2003
    Location:
    Posts: 17,654
    - , - 2-3 - - .
    "else" 1 , , .

    " , "
    - , 2 , , ( ), .
    , .

  25. #25
    Registered User
    Join Date: Jul:2005
    Location: Sofiq
    Posts: 2,798
    Quote Originally Posted by tedych View Post
    - , - 2-3 - - .
    "else" 1 , , .
    .
    Code:
    if() {
    	// 
    } else {
    	//  
    }
    :

    Code:
    if() $a = 1;
    else $a = 2;

    Code:
    $a 		= () ? 1 : 2;
    - . .

Posting Permissions

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

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |