mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2026-01-21 19:32:58 +01:00
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:
26
src/core/byte.ts
Normal file
26
src/core/byte.ts
Normal 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};
|
||||
Reference in New Issue
Block a user