Golang convert string to int - example

Golang convert string to int - example

In Golang, you can convert string to int type using the following functions. strconv.ParseInt(s, base, bitSize) and strconv.Atoi(s)

In Golang, you can convert string to int type using the following functions.

  1. strconv.ParseInt(s, base, bitSize)
  2. strconv.Atoi(s)

Let’s checkout the example of above functions:

1. Golang convert string to int using strconv.ParseInt(s, base, bitSize)

package main

import (

func main() {
    str := "1111"

    n, err := strconv.ParseInt(str, 2, 32)

    if err != nil {
    } else {

The strconv.ParseInt(s, base, bitSize) converts the given string to an integer in the given base (0, 2 to 36) and bit size (0 to 64). The output of the above code will be 15 .

code examples golang

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Static Code Analysis: What It Is? How to Use It?

Static code analysis is a method of debugging by examining source code before a program is run. It's done by analyzing a set of code against a set (or multiple sets) of coding rules. Static code analysis and static analysis are often used interchangeably, along with source code analysis.

How to Find the Stinky Parts of Your Code (Part II)

There are more code smells. Let’s keep changing the aromas. We see several symptoms and situations that make us doubt the quality of our development. Let's look at some possible solutions.

Golang with Examples: Keeping Your Modules Compatible

Learn how to extend Functions and Interfaces without breaking behaviour & ensuring backward compatibility. Golang with Examples: Keeping Your Modules Compatible

Let's Talk About Selling Your Code

In this video, I'll be talking about when do I think code is ready to be sold. 🔴 Subscribe for more https://www.youtube.com/channel/UCMA8gVyu_IkVIixXd2p18NQ?...

Softagram - Making Code Reviews Humane

The story of Softagram is a long one and has many twists. Everything started in a small company long time ago, from the area of static analysis tools development. After many phases, Softagram is focusing on helping developers to get visual feedback on the code change: how is the software design evolving in the pull request under review.