mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2025-12-13 08:22:11 +01:00
Add IpAddress.toBinaryString() method
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
export default {
|
const formatter = {
|
||||||
formatString: function(num: number, kind: string) : string {
|
formatString: function(num: number, kind: string) : string {
|
||||||
return num.toString(getBase(kind || "bin"));
|
return num.toString(getBase(kind || "bin"));
|
||||||
},
|
},
|
||||||
@@ -31,4 +31,8 @@ function getBase(kind:string) : number {
|
|||||||
}
|
}
|
||||||
|
|
||||||
throw new Error("Unsupported kind: " + kind);
|
throw new Error("Unsupported kind: " + kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default formatter;
|
||||||
|
const emBin = formatter.emBin;
|
||||||
|
export {emBin};
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import {emBin} from "../core/formatter";
|
||||||
|
|
||||||
export type OctetNumber = 1 | 2 | 3 | 4;
|
export type OctetNumber = 1 | 2 | 3 | 4;
|
||||||
export type NetworkClass = 'a' | 'b' | 'c' | 'd' | 'e';
|
export type NetworkClass = 'a' | 'b' | 'c' | 'd' | 'e';
|
||||||
|
|
||||||
@@ -33,6 +35,11 @@ export class IpAddress {
|
|||||||
return `${this.firstByte}.${this.secondByte}.${this.thirdByte}.${this.fourthByte}`;
|
return `${this.firstByte}.${this.secondByte}.${this.thirdByte}.${this.fourthByte}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toBinaryString() {
|
||||||
|
|
||||||
|
return `${emBin(this.firstByte)}).${emBin(this.secondByte)}.${emBin(this.thirdByte)}.${emBin(this.fourthByte)}`;
|
||||||
|
}
|
||||||
|
|
||||||
clone(): IpAddress {
|
clone(): IpAddress {
|
||||||
return new IpAddress(this.firstByte, this.secondByte, this.thirdByte, this.fourthByte);
|
return new IpAddress(this.firstByte, this.secondByte, this.thirdByte, this.fourthByte);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user