mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2025-12-10 06:52:05 +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 {
|
||||
return num.toString(getBase(kind || "bin"));
|
||||
},
|
||||
@@ -32,3 +32,7 @@ function getBase(kind:string) : number {
|
||||
|
||||
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 NetworkClass = 'a' | 'b' | 'c' | 'd' | 'e';
|
||||
|
||||
@@ -33,6 +35,11 @@ export class IpAddress {
|
||||
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 {
|
||||
return new IpAddress(this.firstByte, this.secondByte, this.thirdByte, this.fourthByte);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user