Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C# Data Types
  • C# Decision Making
  • C# Methods
  • C# Delegates
  • C# Constructors
  • C# Arrays
  • C# ArrayList
  • C# String
  • C# Tuple
  • C# Indexers
  • C# Interface
  • C# Multithreading
  • C# Exception
Open In App
Next Article:
C# Program for Converting Hexadecimal String to Integer
Next article icon

C# Program to Convert the Octal String to an Integer Number

Last Updated : 22 Jun, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

Given an octal number as input, we need to write a program to convert the given octal number into equivalent integer. To convert an octal string to an integer, we have to use Convert.ToInt32() function to convert the values.

Examples:

  Input : 202  Output : 130    Input : 660  Output : 432  

Convert the item to an integer using base value 8 by using a foreach loop .

Program 1:




// C# program to convert an array 
// of octal strings to integers
using System;
using System.Text;
  
class Prog {
  
    static void Main(string[] args)
    {
        string[] str = { "121", "202", "003" };
        int num1 = 0;
        try {
  
            // using foreach loop to access each items
            // and converting to integer numbers
            foreach(string item in str)
            {
                num1 = Convert.ToInt32(item, 8);
                Console.WriteLine(num1);
            }
        }
        catch (Exception ex) {
            Console.WriteLine(ex.ToString());
        }
    }
}
 
 

Output:

  81  130  3  

Program 2:




// C# program to convert an array 
// of octal strings to integers
using System;
using System.Text;
  
namespace geeks {
  
class Prog {
  
    static void Main(string[] args)
    {
        string[] str = { "111", "543", "333", "607", "700" };
        int num2 = 0;
        try {
  
            // using foreach loop to access each items
            // and converting to integer numbers
            foreach(string item in str)
            {
                num2 = Convert.ToInt32(item, 8);
                Console.WriteLine(num2);
            }
        }
        catch (Exception ex) {
            Console.WriteLine(ex.ToString());
        }
    }
}
}
 
 

Output:

  73  355  219  391  448  


Next Article
C# Program for Converting Hexadecimal String to Integer

S

shivanisinghss2110
Improve
Article Tags :
  • C#
  • C# Programs

Similar Reads

  • C# Program to Convert a Binary String to an Integer
    Given an binary string as input, we need to write a program to convert the binary string into equivalent integer. To convert an binary string to integer, we have to use Convert.ToInt32(String, Base/Int32) function to convert the values. The base of the binary is 2. Syntax: Convert.ToInt32(String, Ba
    2 min read
  • C# Program for Converting Hexadecimal String to Integer
    Given an hexadecimal number as input, we need to write a program to convert the given hexadecimal number into equivalent integer. To convert an hexadecimal string to integer, we have to use Convert.ToInt32() function to convert the values. Syntax: Convert.ToInt32(input_string, Input_base); Here, inp
    2 min read
  • C Program For Double to String Conversion
    To convert double to string in C language, we will use the sprintf function as follows: Input: n = 456321.7651234 Output: string: 456321.7651234 Method: Using sprintf By specifying the precision in sprintf, we can convert double to string or character array with custom precision. We can use sprintf
    1 min read
  • C Program to Convert Decimal to Octal
    Given a decimal number as input, we need to write a program to convert the given decimal number into an equivalent octal number. i.e convert the number with base value 10 to base value 8. The base value of a number system determines the number of digits used to represent a numeric value. For example
    3 min read
  • C Program to count the number of zeros from 0 to N
    Given a number N, the task is to write C program to count the number of zeros from 0 to N. Examples: Input: N = 10 Output: 2 Explanation: The number with zeros are 0, 10 till 10. Hence the count of zeros is 2. Input: N = 20 Output: 3 Explanation: The number with zeros are 0, 10, 20 till 20. Hence th
    2 min read
  • C Program to Print the Length of a String using Pointers
    C language provides a built-in function strlen() but in this article, we will learn how to find and print the length of the string using pointers in C. The easiest method to find the length of a string using pointers is by calculating difference between the pointers to the first and last character o
    2 min read
  • How to Convert an Integer to a String in C?
    Write a C program to convert the given integer value to string. Examples Input: 1234Output: "1234"Explanation: The integer 1234 is converted to the string "1234". Input: -567Output: "-567"Explanation: The integer -567 is converted to the string "-567". Different Methods to Convert an Integer to a St
    4 min read
  • C Program For Long to String Conversion
    To convert the long to string in C language we will use the following 2 approaches: Using Macros with sprintfUsing sprintf Input: long = 1234 Output: string 12341. Using Macros and sprintf C/C++ Code // C Program for Long to // String Conversion #include <stdio.h> #include <string.h> #de
    1 min read
  • Converting String to Long in C
    Here, we will see how to build a C Program For String to Long Conversion using strtol() function. Syntax: long int strtol(char *string, char **ptr, int base)The first argument is given as a stringThe second argument is a reference to an object of type char*The third argument denotes the base in whic
    4 min read
  • C Program For Octal to Decimal Conversion
    The number system is one of the ways to represent numbers. Every number system has its own base or radix. For example, Binary, Octal, Decimal, and Hexadecimal Number systems are some of the number systems and are also used in microprocessor programming. These numbers are easy to convert from one sys
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences