commit e56776ce0f05704234e5934726192291ffa47440 parent 67d6432b25e66ba70d1d639a4e3c938e6d7939f4 Author: Amit Dutta <amitdutta4255@gmail.com> Date: Fri, 16 Jan 2026 20:43:29 +0530 [2026-01-16] : .\Semester_1\assignment-primary : edited a assignment file Diffstat:
| M | Semester_1/assignment-primary/Assignment.docx | | | 0 | |
| M | Semester_1/assignment-primary/Assignment.pdf | | | 0 | |
| M | Semester_1/assignment-primary/assignment-p-08.c | | | 24 | +++++++----------------- |
| M | docs/index.html | | | 24 | ++++++++---------------- |
4 files changed, 15 insertions(+), 33 deletions(-)
diff --git a/Semester_1/assignment-primary/Assignment.docx b/Semester_1/assignment-primary/Assignment.docx Binary files differ. diff --git a/Semester_1/assignment-primary/Assignment.pdf b/Semester_1/assignment-primary/Assignment.pdf Binary files differ. diff --git a/Semester_1/assignment-primary/assignment-p-08.c b/Semester_1/assignment-primary/assignment-p-08.c @@ -39,25 +39,16 @@ int main() int countSetBits(int num) { int count = 0; - if (num < 0) + int mask= 1; + int i = 1; + while (i <= 16) { - printf("\nOnly positive numbers are allowed to maintain consistency. \nUsing absolute value %d", -num); - num = -num; - } - while (num > 0) - { - if (num & 1) + if (num & mask) { count++; } - num >>= 1; - /* - Another method to do the above bitwise calculation... - if(num % 2 == 1) { - count++; - } - num /= 2; - */ + mask <<= 1; + i++; } return count; -}- \ No newline at end of file +} diff --git a/docs/index.html b/docs/index.html @@ -942,28 +942,20 @@ int main() int countSetBits(int num) { int count = 0; - if (num < 0) + int mask= 1; + int i = 1; + while (i <= 16) { - printf("\nOnly positive numbers are allowed to maintain consistency. \nUsing absolute value %d", -num); - num = -num; - } - while (num > 0) - { - if (num & 1) + if (num & mask) { count++; } - num >>= 1; - /* - Another method to do the above bitwise calculation... - if(num % 2 == 1) { - count++; - } - num /= 2; - */ + mask <<= 1; + i++; } return count; -}</div> +} +</div> </div> <div class="file-item flex items-center justify-between px-3 py-2 hover:bg-white hover:shadow-sm rounded-lg transition-all group border border-transparent hover:border-slate-100 mb-1">