Coding Test

[프로그래머스] 이진수 더하기 (Kotlin)

SeungYong.Lee 2023. 4. 11. 22:01
반응형

문제 링크

https://school.programmers.co.kr/learn/courses/30/lessons/120885

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

 

Integer의 parseInt(s, radix) 함수를 통해 계산하면 된다.

radix는 몇 진수로 반환할 것인지를 지정하는 것이다.

fun parseIntTwo(bin1: String, bin2: String): String
    = Integer.toBinaryString(Integer.parseInt(bin1, 2) + Integer.parseInt(bin2, 2))

계산 이후에는 다시 정수를 이진수로 표현하기 위해 toBinaryString을 활용한다.

반응형