Added Bit Calculation Page

This commit is contained in:
Md.Mosiur Rahman
2025-01-26 20:58:37 +06:00
parent fb5a7f3e6b
commit 65697be257
7 changed files with 115 additions and 7 deletions

View File

@@ -0,0 +1,16 @@
<div class="container">
<div class="units">
<div class="unit" (click)="onUnitClick('bit')">Bits</div>
<div class="unit" (click)="onUnitClick('bytes')">Bytes</div>
<div class="unit" (click)="onUnitClick('mb')">MegaBytes</div>
<div class="unit" (click)="onUnitClick('gb')">GigaBytes</div>
<div class="unit" (click)="onUnitClick('pb')">PetaBytes</div>
</div>
<div class="input">
<label for="cal-value">Enter Value: </label>
<input type="text" id="cal-value" class=form-control name="calc-value" [(ngModel)]="value"><span> GB</span>
</div>
<div class="output">
<p>{{ value * factor }} {{selectedUnit}}</p>
</div>
</div>

View File

@@ -0,0 +1,29 @@
.container {
margin: 2rem;
.units{
display: flex;
padding-bottom: 2rem;
.unit{
padding: 1rem;
cursor: pointer;
&:hover{
background-color: lightcoral;
border-radius: 10px;
}
}
}
}
label {
padding-right: 1rem;
}
input{
border: none;
border-bottom: 2px solid black;
border-radius: 5px;
padding-left: 1rem;
width: 20%;
}

View File

@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { BitComponent } from './bit.component';
describe('BitComponent', () => {
let component: BitComponent;
let fixture: ComponentFixture<BitComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [BitComponent]
})
.compileComponents();
fixture = TestBed.createComponent(BitComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,45 @@
import { CommonModule } from '@angular/common';
import { Component, OnInit } from '@angular/core';
import { FormsModule } from '@angular/forms';
@Component({
selector: 'app-bit',
standalone: true,
imports: [CommonModule,FormsModule],
templateUrl: './bit.component.html',
styleUrl: './bit.component.scss'
})
export class BitComponent implements OnInit {
value: number = 0;
selectedUnit: string = "";
factor: number = 0;
ngOnInit(): void {
}
onUnitClick(unit: string){
this.selectedUnit = unit;
switch (unit) {
case 'bit':
this.factor = 1024 ** 2 * 8 ;
break;
case 'bytes':
this.factor = 1024 ** 2 ;
break;
case 'mb':
this.factor = 1024 ** 1 ;
break;
case 'gb':
this.factor = 1 ;
break;
case 'pb':
this.factor = 1/1024 ;
break;
default:
break;
}
}
}