bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

luc101.c (1529B)


      1 /*
      2  * Author  : Amit Dutta <amitdutta4255@gmail.com>
      3  * Date    : 08 Feb 2026
      4  * Repo    : https://github.com/notamitgamer/bsc
      5  * License : MIT License (See the LICENSE file for details)
      6  */
      7 
      8 /* Decode student information (Year, Stream, Room No) packed into an integer array.
      9 */
     10 /* Let Us C, Chap- 21 (Operations on Bits), Qn No.: A(c) */
     11 
     12 /* This file is auto-generated by a bot. */
     13 /* This code is not compiled; it is for reference only. */
     14 
     15 
     16 #include <stdio.h>
     17 #include <stdlib.h>
     18 
     19 int main()
     20 {
     21     int data[] = {273, 548, 786, 1096};
     22     int n = 4, i;
     23     int val, year, stream_bits, room;
     24 
     25     for (i = 0; i < n; i++)
     26     {
     27         val = data[i];
     28 
     29         // Room Number: Rest of the bits (Assuming starting from bit 8)
     30         room = val >> 8;
     31 
     32         printf("Student %d (Raw: %d):\n", i + 1, val);
     33         printf("  Room No: %d\n", room);
     34 
     35         // Year: Bits 0-3
     36         printf("  Year: ");
     37         if (val & (1 << 0)) printf("1st Year");
     38         else if (val & (1 << 1)) printf("2nd Year");
     39         else if (val & (1 << 2)) printf("3rd Year");
     40         else if (val & (1 << 3)) printf("4th Year");
     41         else printf("Unknown");
     42         printf("\n");
     43 
     44         // Stream: Bits 4-7 (Mech, Chem, Elec, CS)
     45         printf("  Stream: ");
     46         if (val & (1 << 4)) printf("Mechanical");
     47         else if (val & (1 << 5)) printf("Chemical");
     48         else if (val & (1 << 6)) printf("Electronics");
     49         else if (val & (1 << 7)) printf("CS");
     50         else printf("Unknown");
     51         printf("\n\n");
     52     }
     53 
     54     return 0;
     55 }
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror