SHARE
TWEET

Data Overflow

valkata Jun 7th, 2017 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace dataOverflow
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             decimal num1 = decimal.Parse(Console.ReadLine());
  14.             decimal num2 = decimal.Parse(Console.ReadLine());
  15.             int bytes = 255;
  16.             int ushorts = 65535;
  17.             uint ints = 4294967295;
  18.             decimal overflow = 0;
  19.  
  20.             decimal big = Math.Max(num1, num2);
  21.             decimal small=Math.Min(num1, num2);
  22.             string bigger = (big <= ushorts? "bigger type: ushort" :
  23.                 big <= ints ? "bigger type: uint" :  "bigger type: ulong");
  24.             string smaller = (small <= bytes ? "smaller type: byte" : small <= ushorts ? "smaller type: ushort" :
  25.                 "smaller type: uint");
  26.             Console.WriteLine(bigger);
  27.             Console.WriteLine(smaller);
  28.  
  29.             if(small <= bytes)
  30.             {
  31.                 overflow = big / bytes;
  32.                 Console.WriteLine($"{big} can overflow byte {Math.Round(overflow)} times");
  33.             }
  34.             else if( small <= ushorts)
  35.             {
  36.                 overflow = big / ushorts;
  37.                 Console.WriteLine($"{big} can overflow ushort {Math.Round(overflow)} times");
  38.             }
  39.             else
  40.             {
  41.                 overflow = big / ints;
  42.                 Console.WriteLine($"{big} can overflow uint {Math.Round(overflow)} times");
  43.             }
  44.            
  45.            
  46.  
  47.  
  48.         }
  49.     }
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top