//
//  NSDataToInteger.h
//  Tests
//
//  Created by Georg Seifert on 2.3.08.
//  Copyright 2008 schriftgestaltung.de. All rights reserved.
//
NSString *num2binary(NSInteger l, short bits);
NSInteger binary2num(NSString *bin);
NSInteger otRound(CGFloat value);
NSString *floatToFixedToStr(CGFloat value, int precisionBits);
NSString *fixedToStr(NSInteger value, int precisionBits);

uint8_t GSDataUnsignedInt8AtOffset(const void *bytes, NSUInteger *offsetPtr, size_t length);
int8_t GSDataInt8AtOffset(const void *bytes, NSUInteger *offsetPtr, size_t length);
uint16_t GSDataUnsignedInt16AtOffset(const void *bytes, NSUInteger *offsetPtr, size_t length);
int16_t GSDataInt16AtOffset(const void *bytes, NSUInteger *offsetPtr, size_t length);
uint32_t GSDataUnsignedInt32AtOffset(const void *bytes, NSUInteger *offsetPtr, size_t length);
int32_t GSDataInt32AtOffset(const void *bytes, NSUInteger *offsetPtr, size_t length);

@interface NSData (DataToInteger)

- (u_int8_t)unsignedInt8AtOffset:(NSUInteger *)offsetPtr;
- (int8_t)int8AtOffset:(NSUInteger *)offsetPtr;

- (int16_t)int16AtOffset:(NSUInteger *)offsetPtr;
- (u_int16_t)unsignedInt16AtOffset:(NSUInteger *)offsetPtr;

- (int32_t)int32AtOffset:(NSUInteger *)offsetPtr;
- (u_int32_t)unsignedInt32AtOffset:(NSUInteger *)offsetPtr;

- (NSUInteger)unsignedIntegerAtOffset:(NSUInteger *)offsetPtr ofSize:(NSUInteger)size;

- (NSData *)subdataFromIndex:(NSUInteger)aIndex;

- (NSString *)hex;

@end

@interface NSMutableData (Writing)

- (void)appendUInt8:(uint8_t)value;
- (void)appendInt8:(int8_t)value;
- (void)appendUInt16:(uint16_t)value;
- (void)appendInt16:(int16_t)value;
- (void)appendUInt24:(uint32_t)value;
- (void)appendInt24:(int32_t)value;
- (void)appendUInt32:(uint32_t)value;
- (void)appendInt32:(int32_t)value;

- (void)appendUInt:(int32_t)value ofSize:(uint8_t)size;
- (void)appendInt:(int32_t)value ofSize:(uint8_t)size;

@end

@interface NSData (Writing)

+ (NSData *)dataWithUInt8:(uint8_t)value;
+ (NSData *)dataWithInt8:(int8_t)value;
+ (NSData *)dataWithUInt16:(uint16_t)value;
+ (NSData *)dataWithInt16:(int16_t)value;
+ (NSData *)dataWithUInt24:(uint32_t)value;
+ (NSData *)dataWithUInt32:(uint32_t)value;
+ (NSData *)dataWithInt32:(int32_t)value;

@end
