diff --git a/bin-to-dec/.gitignore b/bin-to-dec/.gitignore
new file mode 100644
index 00000000..153c9335
--- /dev/null
+++ b/bin-to-dec/.gitignore
@@ -0,0 +1,29 @@
+HELP.md
+/target/
+!.mvn/wrapper/maven-wrapper.jar
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+/build/
+
+### VS Code ###
+.vscode/
diff --git a/bin-to-dec/pom.xml b/bin-to-dec/pom.xml
new file mode 100644
index 00000000..b93c9b19
--- /dev/null
+++ b/bin-to-dec/pom.xml
@@ -0,0 +1,67 @@
+
+
+ 4.0.0
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.1.4.RELEASE
+
+
+ com.sortinn
+ bin-to-dec
+ 0.0.1-SNAPSHOT
+ bin-to-dec
+ Demo project for Spring Boot
+
+
+ 1.8
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-thymeleaf
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-webflux
+
+
+
+ org.projectlombok
+ lombok
+ true
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ io.projectreactor
+ reactor-test
+ test
+
+
+
+ com.google.guava
+ guava
+ 27.0.1-jre
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+
+
diff --git a/bin-to-dec/src/main/java/com/sortinn/bintodec/BinToDecApplication.java b/bin-to-dec/src/main/java/com/sortinn/bintodec/BinToDecApplication.java
new file mode 100644
index 00000000..b380dcf8
--- /dev/null
+++ b/bin-to-dec/src/main/java/com/sortinn/bintodec/BinToDecApplication.java
@@ -0,0 +1,13 @@
+package com.sortinn.bintodec;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class BinToDecApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(BinToDecApplication.class, args);
+ }
+
+}
diff --git a/bin-to-dec/src/main/java/com/sortinn/bintodec/controller/BinToDecController.java b/bin-to-dec/src/main/java/com/sortinn/bintodec/controller/BinToDecController.java
new file mode 100644
index 00000000..abff47e7
--- /dev/null
+++ b/bin-to-dec/src/main/java/com/sortinn/bintodec/controller/BinToDecController.java
@@ -0,0 +1,32 @@
+package com.sortinn.bintodec.controller;
+
+import com.sortinn.bintodec.service.BinToDecService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.servlet.ModelAndView;
+
+import javax.annotation.Resource;
+
+/**
+ * @author tian.gao
+ * @create 2019.04.22 11:47 PM
+ **/
+@Slf4j
+@Controller
+@RequestMapping("/cal")
+public class BinToDecController {
+
+ @Resource
+ private BinToDecService binToDecService;
+
+ @PostMapping("/b2d/{binary}")
+ public ModelAndView b2d(@PathVariable("binary") String binary) {
+ Integer res = binToDecService.binToDecConvert(binary);
+ ModelAndView modelAndView = new ModelAndView("home-list");
+ modelAndView.addObject("res", res);
+ return modelAndView;
+ }
+}
diff --git a/bin-to-dec/src/main/java/com/sortinn/bintodec/service/BinToDecService.java b/bin-to-dec/src/main/java/com/sortinn/bintodec/service/BinToDecService.java
new file mode 100644
index 00000000..bc46ce15
--- /dev/null
+++ b/bin-to-dec/src/main/java/com/sortinn/bintodec/service/BinToDecService.java
@@ -0,0 +1,52 @@
+package com.sortinn.bintodec.service;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.logging.log4j.util.Strings;
+import org.springframework.stereotype.Service;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * @author tian.gao
+ * @create 2019.04.22 11:47 PM
+ **/
+@Slf4j
+@Service
+public class BinToDecService {
+
+ private static final int MAX_LENGTH = 8;
+
+ public Integer binToDecConvert(String binary) {
+ if (Strings.isEmpty(binary)) {
+ log.error("binary empty");
+ return null;
+ }
+ if (binary.length() > MAX_LENGTH) {
+ log.error("more than max length");
+ return null;
+ }
+
+ String regex = "^[01]+$";
+ Pattern pattern = Pattern.compile(regex);
+ Matcher matcher = pattern.matcher(binary);
+ Double res = 0.0;
+
+ if (matcher.find()) {
+ String[] binaryArr = binary.split("");
+ int length = binaryArr.length;
+ for (int i = 0; i < length; i++) {
+ res += Integer.parseInt(binaryArr[i]) * Math.pow(2, length - 1 - i);
+ }
+ } else {
+ log.error("input is not binary number");
+ return null;
+ }
+ return res.intValue();
+
+ }
+
+ public static void main(String[] args) {
+ System.out.println(new BinToDecService().binToDecConvert("11111110"));
+ }
+}
diff --git a/bin-to-dec/src/main/resources/application.properties b/bin-to-dec/src/main/resources/application.properties
new file mode 100644
index 00000000..8b137891
--- /dev/null
+++ b/bin-to-dec/src/main/resources/application.properties
@@ -0,0 +1 @@
+
diff --git a/bin-to-dec/src/main/resources/templates/home-list.html b/bin-to-dec/src/main/resources/templates/home-list.html
new file mode 100644
index 00000000..39ca5368
--- /dev/null
+++ b/bin-to-dec/src/main/resources/templates/home-list.html
@@ -0,0 +1,114 @@
+
+
+
+
+
+
+
+
+
+ Home
+
+
+
+
十进制计算器
+
可二进制转换转换为十进制
+
+
+
+
+
+
+
+
+
+
+
+
+ | 用户id |
+ 用户名 |
+ 性别 |
+ 年龄 |
+ 备注 |
+ 是否可用 |
+ 操作 |
+
+
+
+
+
+ |
+ |
+ |
+ |
+ |
+ |
+
+ 编辑
+ 删除
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/bin-to-dec/src/test/java/com/sortinn/bintodec/BinToDecApplicationTests.java b/bin-to-dec/src/test/java/com/sortinn/bintodec/BinToDecApplicationTests.java
new file mode 100644
index 00000000..85bab1d2
--- /dev/null
+++ b/bin-to-dec/src/test/java/com/sortinn/bintodec/BinToDecApplicationTests.java
@@ -0,0 +1,29 @@
+package com.sortinn.bintodec;
+
+import com.sortinn.bintodec.service.BinToDecService;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import javax.annotation.Resource;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class BinToDecApplicationTests {
+
+ @Resource
+ private BinToDecService binToDecService;
+
+ @Test
+ public void contextLoads() {
+ }
+
+ @Test
+ public void b2d_test() {
+ Integer res = binToDecService.binToDecConvert("11111111");
+ System.out.println(res);
+ }
+
+}