diff --git a/src/app/backend/berechnung.ts b/src/app/backend/berechnung.ts index c09bd88..ed3667a 100644 --- a/src/app/backend/berechnung.ts +++ b/src/app/backend/berechnung.ts @@ -18,13 +18,33 @@ export class Berechnung { return this.binArr.join(".") } + binToDec(bin: string) { + var arr = bin.split(" ") + alert(arr) + let binNum = "" + for (let index = 0; index < arr.length; index++) { + binNum += parseInt(arr[index], 2).toString(); + + } + return binNum; + + } + subNetMask(prefix: number) { let mask = "" return mask; } - broadCast(arr: any[]) { - + broadCastBin(binIp: string, prefix: number) { + var arr = binIp.split('.'); + let prefixIp = arr.join(""); + let hostbin = prefixIp.slice(0, prefix); + hostbin = hostbin + "1".repeat(32 - prefix); + for (let i = 8; i <= hostbin.length; i += 8) { + hostbin = [hostbin.slice(0, i), " ", hostbin.slice(i)].join('') + i++ + } + return hostbin } netId(mask: string) { diff --git a/src/app/input/input.component.html b/src/app/input/input.component.html index d3ca544..e10eef7 100644 --- a/src/app/input/input.component.html +++ b/src/app/input/input.component.html @@ -12,5 +12,5 @@ - + \ No newline at end of file diff --git a/src/app/input/input.component.ts b/src/app/input/input.component.ts index 1d2fc4d..dffc278 100644 --- a/src/app/input/input.component.ts +++ b/src/app/input/input.component.ts @@ -1,5 +1,6 @@ import { Component, OnInit } from '@angular/core'; import { Berechnung } from '../backend/berechnung'; +import { MyserviceService } from '../myservice.service'; @Component({ selector: 'app-input', @@ -11,18 +12,18 @@ export class InputComponent implements OnInit { ipv4_eingabe: string = ""; prefix_selection: number = 0; - - constructor() { + constructor(public service: MyserviceService) { for (let i = 0; i <= 32; i++) { this.counter.push(i); } } onClick() { - var berechnung = new Berechnung; - let number = berechnung.decToBin(this.ipv4_eingabe) - alert(number) - + var calc = new Berechnung; + this.service.bin_dec_dict.Ipv4.bin = calc.decToBin(this.ipv4_eingabe) + this.service.bin_dec_dict.Ipv4.dec = this.ipv4_eingabe; + this.service.bin_dec_dict.Broadcast.bin = calc.broadCastBin(this.service.bin_dec_dict.Ipv4.bin, this.prefix_selection); + this.service.bin_dec_dict.Broadcast.dec = calc.binToDec(this.service.bin_dec_dict.Broadcast.bin) } ngOnInit(): void { diff --git a/src/app/myservice.service.ts b/src/app/myservice.service.ts index 3376bf4..6c8cb07 100644 --- a/src/app/myservice.service.ts +++ b/src/app/myservice.service.ts @@ -4,6 +4,31 @@ import { Injectable } from '@angular/core'; providedIn: 'root' }) export class MyserviceService { - + bin_dec_dict = { + Ipv4: { + dec: "", + bin: "" + }, + Subnet: { + dec: "", + bin: "" + }, + Broadcast: { + dec: "", + bin: "" + }, + NetID: { + dec: "", + bin: "" + }, + FirstIP: { + dec: "", + bin: "" + }, + LastIP: { + dec: "", + bin: "" + } + } constructor() { } } diff --git a/src/app/output/output.component.html b/src/app/output/output.component.html index 6aa43a3..6db2ac2 100644 --- a/src/app/output/output.component.html +++ b/src/app/output/output.component.html @@ -1,7 +1,42 @@ -