{"id":22765189,"url":"https://github.com/vidundergunder/simulated-8-bit-adder","last_synced_at":"2026-05-02T19:37:45.745Z","repository":{"id":135435440,"uuid":"361549053","full_name":"VidunderGunder/simulated-8-bit-adder","owner":"VidunderGunder","description":"Simulated 8-bit Ripple Carry Adder implemented in TypeScript. ","archived":false,"fork":false,"pushed_at":"2021-04-25T22:32:02.000Z","size":2331,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-05T12:13:15.701Z","etag":null,"topics":["8-bit","circuit","crash-course","electronics","logic","logic-gates","simulation","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/VidunderGunder.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-25T22:05:48.000Z","updated_at":"2021-04-25T22:34:20.000Z","dependencies_parsed_at":null,"dependency_job_id":"91c4b150-7902-4a87-bf17-8f9a543a1d17","html_url":"https://github.com/VidunderGunder/simulated-8-bit-adder","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VidunderGunder%2Fsimulated-8-bit-adder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VidunderGunder%2Fsimulated-8-bit-adder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VidunderGunder%2Fsimulated-8-bit-adder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VidunderGunder%2Fsimulated-8-bit-adder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VidunderGunder","download_url":"https://codeload.github.com/VidunderGunder/simulated-8-bit-adder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246301994,"owners_count":20755514,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["8-bit","circuit","crash-course","electronics","logic","logic-gates","simulation","typescript"],"created_at":"2024-12-11T12:12:06.916Z","updated_at":"2026-05-02T19:37:45.718Z","avatar_url":"https://github.com/VidunderGunder.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simulated 8-bit Adder in TypeScript\n\nPersonal experiment to practice TypeScript. Playing around with overload signatures, bitwise operators and logic.\n\nType checks feel bloated to me - any tips to clean them up would be greatly appreciated!\n\nInspired by [Crash Course's ALU-video](https://youtu.be/1I5ZMmrOfnA).\n\n---\n\n[![picture 1](images/diagram.png)](https://youtu.be/1I5ZMmrOfnA)\n\n\u003cp align=\"center\"\u003e\u003csmall\u003e\u003ci\u003eDiagram from Crash Course's video illustrating an 8-bit ripple carry adder\u003c/i\u003e\u003c/small\u003e\u003c/p\u003e\n\n---\n\n```ts\n// ---------------------\n// SIMULATED LOGIC GATES\n// ---------------------\n\ntype BitInt = 0 | 1;\ntype BitString = \"0\" | \"1\";\n\nfunction xor(a: boolean, b: boolean): boolean;\nfunction xor(a: BitInt, b: BitInt): BitInt;\nfunction xor(a: BitString, b: BitString): BitString;\nfunction xor(a: any, b: any): any {\n  if (typeof a !== typeof b) throw \"Inputs must be of same type.\";\n  if (typeof a === \"boolean\" \u0026\u0026 typeof b === \"boolean\") return a !== b;\n  if (typeof a === \"number\" \u0026\u0026 typeof b === \"number\") return a ^ b;\n  if (typeof a === \"string\" \u0026\u0026 typeof b === \"string\")\n    return String(Number(a) ^ Number(b));\n}\n\nfunction and(a: boolean, b: boolean): boolean;\nfunction and(a: BitInt, b: BitInt): BitInt;\nfunction and(a: BitString, b: BitString): BitString;\nfunction and(a: any, b: any): any {\n  if (typeof a !== typeof b) throw \"Inputs must be of same type.\";\n  if (typeof a === \"boolean\" \u0026\u0026 typeof b === \"boolean\") return a \u0026\u0026 b;\n  if (typeof a === \"number\" \u0026\u0026 typeof b === \"number\") return a \u0026 b;\n  if (typeof a === \"string\" \u0026\u0026 typeof b === \"string\")\n    return String(Number(a) \u0026 Number(b));\n}\n\nfunction or(a: boolean, b: boolean): boolean;\nfunction or(a: BitInt, b: BitInt): BitInt;\nfunction or(a: BitString, b: BitString): BitString;\nfunction or(a: any, b: any): any {\n  if (typeof a !== typeof b) throw \"Inputs must be of same type.\";\n  if (typeof a === \"boolean\" \u0026\u0026 typeof b === \"boolean\") return a || b;\n  if (typeof a === \"number\" \u0026\u0026 typeof b === \"number\") return a | b;\n  if (typeof a === \"string\" \u0026\u0026 typeof b === \"string\")\n    return String(Number(a) | Number(b));\n}\n\n// ---------------------\n// SIMULATED HALF ADDER\n// ---------------------\n\nfunction halfAdder(a: boolean, b: boolean): [boolean, boolean];\nfunction halfAdder(a: BitInt, b: BitInt): [BitInt, BitInt];\nfunction halfAdder(a: BitString, b: BitString): [BitString, BitString];\nfunction halfAdder(a: any, b: any): [any, any] {\n  const sum = xor(a, b); // XOR\n  const carry = and(a, b); // AND\n  return [carry, sum];\n}\n\n// ---------------------\n// SIMULATED FULL ADDER\n// ---------------------\n\nfunction fullAdder(a: boolean, b: boolean, c: boolean): [boolean, boolean];\nfunction fullAdder(a: BitInt, b: BitInt, c: BitInt): [BitInt, BitInt];\nfunction fullAdder(\n  a: BitString,\n  b: BitString,\n  c: BitString\n): [BitString, BitString];\nfunction fullAdder(a: any, b: any, c: any): [any, any] {\n  const [c1, s1] = halfAdder(a, b);\n  const [c2, s2] = halfAdder(s1, c);\n  const c3 = xor(c1, c2);\n  return [c3, s2];\n}\n\n// ---------------------\n// SIMULATED 8-bit ADDER\n// ---------------------\n\ntype ByteInt = [BitInt, BitInt, BitInt, BitInt, BitInt, BitInt, BitInt, BitInt];\ntype ByteString = `${BitString}${BitString}${BitString}${BitString}${BitString}${BitString}${BitString}${BitString}`;\ntype ByteBool = [\n  boolean,\n  boolean,\n  boolean,\n  boolean,\n  boolean,\n  boolean,\n  boolean,\n  boolean\n];\n\nfunction add8Bit(a: ByteInt, b: ByteInt): ByteInt;\nfunction add8Bit(a: ByteBool, b: ByteBool): ByteBool;\nfunction add8Bit(a: ByteString, b: ByteString): ByteString;\nfunction add8Bit(a: any, b: any): any {\n  let [c, s] = halfAdder(a[7], b[7]);\n\n  const sum = [\n    undefined,\n    undefined,\n    undefined,\n    undefined,\n    undefined,\n    undefined,\n    undefined,\n    s,\n  ];\n\n  for (let i = 6; i \u003e= 0; i--) {\n    [c, s] = fullAdder(a[i], b[i], c);\n    sum[i] = s;\n  }\n\n  if (typeof a === \"string\" \u0026\u0026 typeof b === \"string\" \u0026\u0026 typeof c == \"string\")\n    return [sum.join(\"\"), c];\n  return [sum, c];\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvidundergunder%2Fsimulated-8-bit-adder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvidundergunder%2Fsimulated-8-bit-adder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvidundergunder%2Fsimulated-8-bit-adder/lists"}