Subnet command (#17)

* Started working on subnets

* Basic version of the subnet command

* Improved subnet command

* almost done with subnets

* improve positioning
This commit is contained in:
Borys Levytskyi
2021-01-16 11:33:45 +02:00
committed by GitHub
parent 0cd9c8049b
commit 478ecbfb60
24 changed files with 659 additions and 332 deletions

26
src/core/byte.ts Normal file
View File

@@ -0,0 +1,26 @@
function flipBitsToZero(byte: number, numberOfBits : number) : number {
if(numberOfBits == 0)
return byte;
const zerouOutMask = Math.pow(2, 8-numberOfBits)-1<<numberOfBits; // E.g. 11111000 for flipping first three bits
const result = byte & zerouOutMask;
return result;
}
// TODO: continue here to implement getting broadcast address
function flipBitsToOne(byte : number, numberOfBits : number) : number {
if(numberOfBits == 0) return byte;
const zerouOutMask = Math.pow(2, numberOfBits)-1; // E.g. 00000111 for flipping first three bits
const result = byte | zerouOutMask;
return result;
}
function createSubnetMaskByte(numberOfBits: number) {
return 255<<(8-numberOfBits)&255;;
}
export {flipBitsToZero, createSubnetMaskByte, flipBitsToOne};