Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright 2014 ZXing authors
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "ZXAztecSimpleToken.h"
  17. #import "ZXBitArray.h"
  18. @interface ZXAztecSimpleToken ()
  19. // For normal words, indicates value and bitCount
  20. @property (nonatomic, assign, readonly) int16_t value;
  21. @property (nonatomic, assign, readonly) int16_t bitCount;
  22. @end
  23. @implementation ZXAztecSimpleToken
  24. - (id)initWithPrevious:(ZXAztecToken *)previous value:(int)value bitCount:(int)bitCount {
  25. if (self = [super initWithPrevious:previous]) {
  26. _value = (int16_t)value;
  27. _bitCount = (int16_t)bitCount;
  28. }
  29. return self;
  30. }
  31. - (void)appendTo:(ZXBitArray *)bitArray text:(ZXByteArray *)text {
  32. [bitArray appendBits:self.value numBits:self.bitCount];
  33. }
  34. - (NSString *)description {
  35. int value = self.value & ((1 << self.bitCount) - 1);
  36. value |= 1 << self.bitCount;
  37. NSMutableString *str = [NSMutableString string];
  38. for (int i = value | (1 << self.bitCount); i > 0; i >>= 1) {
  39. [str insertString:((i & 1) ? @"1" : @"0") atIndex:0];
  40. }
  41. return [NSString stringWithFormat:@"<%@>", [str substringFromIndex:1]];
  42. }
  43. @end