diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..bda3ac9 --- /dev/null +++ b/.clang-format @@ -0,0 +1,243 @@ +Language: Cpp +# BasedOnStyle: WebKit +AccessModifierOffset: -4 +AlignAfterOpenBracket: DontAlign +AlignArrayOfStructures: None +AlignConsecutiveAssignments: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: true +AlignConsecutiveBitFields: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveMacros: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveShortCaseStatements: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCaseColons: false +AlignEscapedNewlines: Right +AlignOperands: DontAlign +AlignTrailingComments: + Kind: Never + OverEmptyLines: 0 +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowBreakBeforeNoexceptSpecifier: Never +AllowShortBlocksOnASingleLine: Empty +AllowShortCaseLabelsOnASingleLine: false +AllowShortCompoundRequirementOnASingleLine: true +AllowShortEnumsOnASingleLine: true +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +AttributeMacros: + - __capability +BinPackArguments: true +BinPackParameters: true +BitFieldColonSpacing: Both +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterExternBlock: false + AfterFunction: true + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakAdjacentStringLiterals: true +BreakAfterAttributes: Leave +BreakAfterJavaFieldAnnotations: false +BreakArrays: true +BreakBeforeBinaryOperators: All +BreakBeforeConceptDeclarations: Always +BreakBeforeBraces: WebKit +BreakBeforeInlineASMColon: OnlyMultiline +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeComma +BreakInheritanceList: BeforeColon +BreakStringLiterals: true +ColumnLimit: 0 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: false +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + CaseSensitive: false + - Regex: '.*' + Priority: 1 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentAccessModifiers: false +IndentCaseBlocks: false +IndentCaseLabels: false +IndentExternBlock: AfterExternBlock +IndentGotoLabels: true +IndentPPDirectives: None +IndentRequiresClause: true +IndentWidth: 4 +IndentWrappedFunctionNames: false +InsertBraces: false +InsertNewlineAtEOF: false +InsertTrailingCommas: None +IntegerLiteralSeparator: + Binary: 0 + BinaryMinDigits: 0 + Decimal: 0 + DecimalMinDigits: 0 + Hex: 0 + HexMinDigits: 0 +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +KeepEmptyLinesAtEOF: false +LambdaBodyIndentation: Signature +LineEnding: DeriveLF +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: Inner +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 4 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: true +PackConstructorInitializers: BinPack +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakScopeResolution: 500 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyIndentedWhitespace: 0 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Left +PPIndentWidth: -1 +QualifierAlignment: Leave +ReferenceAlignment: Pointer +ReflowComments: true +RemoveBracesLLVM: false +RemoveParentheses: Leave +RemoveSemicolon: false +RequiresClausePosition: OwnLine +RequiresExpressionIndentation: OuterScope +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SkipMacroDefinitionBody: false +SortIncludes: CaseSensitive +SortJavaStaticImport: Before +SortUsingDeclarations: LexicographicNumeric +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceAroundPointerQualifiers: Default +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: true +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeJsonColon: false +SpaceBeforeParens: ControlStatements +SpaceBeforeParensOptions: + AfterControlStatements: true + AfterForeachMacros: true + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: true + AfterOverloadedOperator: false + AfterPlacementOperator: true + AfterRequiresInClause: false + AfterRequiresInExpression: false + BeforeNonEmptyParentheses: false +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: true +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Never +SpacesInContainerLiterals: true +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParens: Never +SpacesInParensOptions: + InCStyleCasts: false + InConditionalStatements: false + InEmptyParentheses: false + Other: false +SpacesInSquareBrackets: false +Standard: Latest +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseTab: Never +VerilogBreakBetweenInstancePorts: true +WhitespaceSensitiveMacros: + - BOOST_PP_STRINGIZE + - CF_SWIFT_NAME + - NS_SWIFT_NAME + - PP_STRINGIZE + - STRINGIZE \ No newline at end of file diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..355e687 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + schedule: + interval: "weekly" \ No newline at end of file diff --git a/.github/workflows/build-and-lint.yml b/.github/workflows/build-and-lint.yml new file mode 100644 index 0000000..31983d4 --- /dev/null +++ b/.github/workflows/build-and-lint.yml @@ -0,0 +1,14 @@ +name: Build and lint + +on: + - push + - pull_request + +jobs: + build-and-lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - name: Check format + run: | + find . -path ./build -prune -o -type f -name '*.[c|h]' -print | xargs clang-format-18 --style=file --dry-run -Werror \ No newline at end of file diff --git a/hw12.binRepr/CMakeLists.txt b/hw12.binRepr/CMakeLists.txt new file mode 100644 index 0000000..32d6ffc --- /dev/null +++ b/hw12.binRepr/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.25) +project(hw12 C) + +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) + +# Создаём библиотеку из файла в поддиректории +add_library(binRepresent binRepresent.c) + +# Создаём исполняемый файл из файла в другой поддиректории +add_executable(main main.c) + +# Линкуем библиотеку +target_link_libraries(main PRIVATE binRepresent) diff --git a/hw12.binRepr/binRepresent.c b/hw12.binRepr/binRepresent.c new file mode 100644 index 0000000..8c40d0a --- /dev/null +++ b/hw12.binRepr/binRepresent.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include "binRepresent.h" + +void binPrint(int num[]) +{ + for (int i = 0; i < 32; i++) { + printf("%d", num[i]); + } + printf("\n"); +} + +void bin(int result[], int number) +{ + int num = number; + if (number < 0) { + num *= -1; + } + int ind = 31; + + while (num != 0) { + result[ind] = num % 2; + num /= 2; + ind--; + } + + if (number < 0) { + for (int i = 1; i < 32; i++) { + result[i] = 1 - result[i]; + } + result[0] = 1; + + int one[32] = { 0 }; + one[31] = 1; + binSumm(result, one, result); + } +} + +int decimal(int num[]) +{ + int decimalNum = 0; + + for (int i = 0; i < 32; i++) { + int degree = 1 << i; + decimalNum += degree * num[31 - i]; + } + return decimalNum; +} + +void binSumm(int result[], int num1[], int num2[]) +{ + int carry = 0; + for (int i = 31; i > -1; i--) { + int sum = num1[i] + num2[i] + carry; + result[i] = sum % 2; + carry = sum / 2; + } +} + +int decSumm(int num1[], int num2[]) +{ + int biSumm[32] = { 0 }; + binSumm(biSumm, num1, num2); + int deSumm = decimal(biSumm); + return deSumm; +} \ No newline at end of file diff --git a/hw12.binRepr/binRepresent.h b/hw12.binRepr/binRepresent.h new file mode 100644 index 0000000..9b03270 --- /dev/null +++ b/hw12.binRepr/binRepresent.h @@ -0,0 +1,7 @@ +#pragma once + +void binPrint(int num[]); +void bin(int result[], int number); +int decimal(int num[]); +void binSumm(int result[], int num1[], int num2[]); +int decSumm(int num1[], int num2[]); diff --git a/hw12.binRepr/main.c b/hw12.binRepr/main.c new file mode 100644 index 0000000..b3681e4 --- /dev/null +++ b/hw12.binRepr/main.c @@ -0,0 +1,82 @@ +#include "binRepresent.h" +#include +#include +#include +#include + +const int length = 32; + +bool run_tests() +{ + int s = 0; + + int number1 = 1; + int number1Bin[32] = { 0 }; + bin(number1Bin, number1); + int number2Bin[32] = { 0 }; + number2Bin[31] = 1; + if (memcmp(number1Bin, number2Bin, length) == 0) { + s++; + } + + int number3 = decimal(number1Bin); + if (number3 == 1) { + s++; + } + + int number4Bin[32] = { 0 }; + bin(number4Bin, -number1); + int number5Bin[32] = { 0 }; + binSumm(number5Bin, number4Bin, number1Bin); + int number6Bin[32] = { 0 }; + if (memcmp(number5Bin, number6Bin, length) == 0) { + s++; + } + + int number7 = decSumm(number4Bin, number1Bin); + if (number7 == 0) { + s++; + } + + return s == 4; +} + +int main(int argc, char** argv) +{ + if (argc == 2 && strcmp(argv[1], "--test") == 0) { + if (!run_tests()) { + printf("Test failed\n"); + return 1; + } else { + printf("Test passed\n"); + return 0; + } + } + + int number1 = 0; + printf("Введите первое число(целое не больше 2^32): "); + scanf("%d", &number1); + int number2 = 0; + printf("Введите второе число(целое не больше 2^32): "); + scanf("%d", &number2); + + int num1Bin[32] = { 0 }; + bin(num1Bin, number1); + int num2Bin[32] = { 0 }; + bin(num2Bin, number2); + + printf("%d в двоичном представлении: ", number1); + binPrint(num1Bin); + printf("%d в двоичном представлении: ", number2); + binPrint(num2Bin); + + int summ[32] = { 0 }; + binSumm(summ, num1Bin, num2Bin); + printf("Сумма в двоичной системе: "); + binPrint(summ); + + int sumDecimal = decimal(summ); + printf("Сумма в десятичной системе %d\n", sumDecimal); + + return 0; +} \ No newline at end of file