uint8_t RF24BLE::recvPacket(uint8_t *input, uint8_t length,uint8_t channel ){ unsigned long time = millis(); while (_radio.available()<=0 && (millis()-time)<RECV_TIMEOUT){delay(1);} if (_radio.available()>0){ _radio.read(input, length); } else { return RF24BLE_TIMEOUT; } uint8_t i, dataLen = length - 3; #if DEBUG == 1 // Packet length includes crc of 3 bytes for (i = 0; i < length; i++){ Serial.print((char)input[i]); } Serial.println(); #endif //reversing the bits of the complete packet for (i = 0; i < length; i++){ input[i] = reverseBits(input[i]); } //de-whiten the packet using the same polynomial bleWhiten(input, length, bleWhitenStart(RF24BLE::chLe[channel])); //reversing bits of the crc for (i = 0; i < 3; i++, dataLen++){ input[dataLen] = reverseBits(input[dataLen]); } #if DEBUG == 1 for (i = 0; i < length; i++){ Serial.print((char)input[i]); } Serial.println(); #endif return checkCRC(input, length); }
int main() { unsigned char c = 0x23; printf("%x %x\n", c, reverseBytes(c)); unsigned int val = 0xdeadbeef; printf("%x %x\n", val, reverseBits(val)); val = 1; printf("%x %x\n", val, reverseBits(val)); }
void main(void) { uint32_t i = reverseBits(2147483649); i = reverseBits(32768); i = reverseBits(43261596); bool palindrome = isPalindrome(-2147447412); palindrome = isPalindrome(2112); palindrome = isPalindrome(2147447412); }
void RF24BLE::blePacketEncode(uint8_t* packet, uint8_t len, uint8_t chan){ // Assemble the packet to be transmitted // Packet length includes pre-populated crc uint8_t i, dataLen = len - 3; BLEcrc(packet, dataLen, packet + dataLen); for (i = 0; i < 3; i++, dataLen++) packet[dataLen] = reverseBits(packet[dataLen]); bleWhiten(packet, len, bleWhitenStart(chan)); for (i = 0; i < len; i++) packet[i] = reverseBits(packet[i]); // the byte order of the packet should be reversed as well }
int main(){ // allocate buffer size for input char buf[MAX_BUFFER_SIZE]; CyGlobalIntEnable; /* Enable global interrupts */ // start UART UART_1_Start(); // print line strcpy(buf, "Established Communication \n \r"); UART_1_UartPutString(buf); uint v4 = 0x56; // hex representation of the integer uint vv4 = reverseBits(v4); // print result // integer to string to be printed sprintf(buf, "%X", vv4); strcat(buf, "\n \r"); UART_1_UartPutString(buf); for(;;){} }
inline int FastFourierTransform::fastReverseBits(int i, int NumBits) { if (NumBits <= MaxFastBits) return gFFTBitTable[NumBits - 1][i]; else return reverseBits(i, NumBits); }
/* * ======== taskLoad ======== */ Void task(UArg arg1, UArg arg2) { UInt count = 1; Int status = Ipc_S_SUCCESS; UInt16 remoteProcId = MultiProc_getId("HOST"); do { status = Ipc_attach(remoteProcId); } while (status < 0); Notify_registerEvent(remoteProcId, 0, SHUTDOWN, (Notify_FnNotifyCbck)notifyCallbackFxn, 0); while (shutdownFlag == FALSE) { Semaphore_pend(sem, BIOS_WAIT_FOREVER); /* Benchmark how long it takes to flip all the bits */ Log_write1(UIABenchmark_start, (xdc_IArg)"Reverse"); reverseBits(buffer, sizeof(buffer)); Log_write1(UIABenchmark_stop, (xdc_IArg)"Reverse"); Log_print1(Diags_USER1, "count = %d", count++); } /* Start shutdown process */ Notify_unregisterEvent(remoteProcId, 0, SHUTDOWN, (Notify_FnNotifyCbck)notifyCallbackFxn, 0); do { status = Ipc_detach(remoteProcId); } while (status < 0); Ipc_stop(); }
void RF24BLE::transmitBegin(){ _radio.disableCRC(); _radio.powerUp(); _radio.setAutoAck(false); _radio.stopListening(); _radio.setAddressWidth(4); _radio.setRetries(0, 0); _radio.setDataRate(RF24_1MBPS); _radio.setPALevel(RF24_PA_MAX); // Set access addresses (TX address in nRF24L01) to BLE advertising 0x8E89BED6 // Both bit and byte orders are reversed for BLE packet format unsigned long address; address = reverseBits(0xD6); address <<= BYTELEN; address |= reverseBits(0xBE); address <<= BYTELEN; address |= reverseBits(0x89); address <<= BYTELEN; address |= reverseBits(0x8E); _radio.openWritingPipe(address); }
/* Driver function to test above function */ int main() { unsigned int x = 0xf0000000; char ch, *chp, **chpp, ***chppp, ****chpppp; printf("Size of int is %ld\n", sizeof(x)); printf("%x\n", reverseBits(x)); chp = &ch; chpp = &chp; chppp = &chpp; chpppp = &chppp; foo (chp, chpp, chpp, chppp); arr_size(); test_operator(); return 1; }
int main (void) { unsigned ui; printf("\n%s%u%s","Please enter an unsigned integer " "(whole number between 0 and ", ULONG_MAX, "):\n\n"); scanf("%u", &ui); displayBits(ui); printf("\n\n%s%u%s", "The result of reversing ", ui, " is:\n"); displayBits(reverseBits(ui)); waitOnInput(); return 0; }
fftLite::fftLite(size_t N_) : cosLUT(nullptr), sinLUT(nullptr), cosLUT_blu(nullptr), sinLUT_blu(nullptr), revBits(nullptr), temps(nullptr), N(0), log2N(0) { if (N_ == 0) return; // prepare for radix-2 Cooley-Tukey if (isPowOf2(N_)) { M = 0; N = N_; } else { // prepare for Bluestein M = N_; N = nextpow2(2 * N_ + 1); cosLUT_blu = new double[M]; sinLUT_blu = new double[M]; for (int i = 0; i < M; ++i) { double temp = M_PI * (((uint64_t)i * i) % (2*M)) / M; //double temp = M_PI * i * i / M; // cos(temp), with large temp cosLUT_blu[i] = cos(temp); sinLUT_blu[i] = sin(temp); } temps = new double[4 * N]; } // radix twiddle factors cosLUT = new double[N / 2]; sinLUT = new double[N / 2]; for (int i = 0; i < N / 2; ++i) { cosLUT[i] = cos(2 * M_PI * i / N); sinLUT[i] = sin(2 * M_PI * i / N); } // pre-compute bit reversal of position index log2N = log2uint(N); revBits = new int[N]; for (int i = 0; i < N; ++i) revBits[i] = reverseBits(i, log2N); }
/* * Initialisation routine - sets up tables and space to work in. * Returns a pointer to internal state, to be used when performing calls. * On error, returns NULL. * The pointer should be freed when it is finished with, by fft_close(). */ fft_state *fft_init(void) { fft_state *state; unsigned int i; state = malloc (sizeof(fft_state)); if(!state) return NULL; for(i = 0; i < FFT_BUFFER_SIZE; i++) { bitReverse[i] = reverseBits(i); } for(i = 0; i < FFT_BUFFER_SIZE / 2; i++) { double j = 2 * PI * i / FFT_BUFFER_SIZE; costable[i] = cos(j); sintable[i] = sin(j); } return state; }
/* * Write the supplied data to the specified strip. * There must be space for the data; we don't check * if strips overlap! * * NB: Image length must be setup before writing. */ tsize_t ExifStripImage::writeRawStrip(exif_uint32 strip, tdata_t data, tsize_t cc) { if (!WRITECHECKSTRIPS) return ((tsize_t) -1); /* * Check strip array to make sure there's space. * We don't support dynamically growing files that * have data organized in separate bitplanes because * it's too painful. In that case we require that * the imagelength be set properly before the first * write (so that the strips array will be fully * allocated above). */ if (strip >= mNStrips) { if (mExifdir->planarConfig() == PLANARCONFIG_SEPARATE) { // Can not grow image by strips when using separate planes return ((tsize_t) -1); } /* * Watch out for a growing image. The value of * strips/image will initially be 1 (since it * can't be deduced until the imagelength is known). */ if (strip >= mStripsperimage) mStripsperimage = EXIFhowmany(mExifdir->imageLength(),mExifdir->rowsPerStrip()); if (!growStrips(1)) return ((tsize_t) -1); } mCurstrip = strip; if (!mExifdir->isFillOrder( mExifio, FILLORDER_MSB2LSB) && (mExifio->flags() & EXIF_NOBITREV) == 0) { reverseBits( (tdata_t)data, cc ); } return ((appendToStrip(strip, (tdata_t) data, cc) == EXIF_OK) ? cc : (tsize_t) -1); }
void FastFourierTransform::initFFT() { if( gFFTBitTable != NULL ){ for(int i=0; i<MaxFastBits; i++) delete[] gFFTBitTable[i]; gFFTBitTable = NULL; } gFFTBitTable = new int *[MaxFastBits]; int len = 2; for (int b = 1; b <= MaxFastBits; b++) { gFFTBitTable[b - 1] = new int[len]; for (int i = 0; i < len; i++) gFFTBitTable[b - 1][i] = reverseBits(i, b); len <<= 1; } }
/* * Initialisation routine - sets up tables and space to work in. * Returns a pointer to internal state, to be used when performing calls. * On error, returns NULL. * The pointer should be freed when it is finished with, by fft_close(). */ fft_state *visual_fft_init(void) { fft_state *p_state; unsigned int i; p_state = malloc( sizeof(*p_state) ); if(! p_state ) return NULL; for(i = 0; i < FFT_BUFFER_SIZE; i++) { p_state->bitReverse[i] = reverseBits(i); } for(i = 0; i < FFT_BUFFER_SIZE / 2; i++) { float j = 2 * PI * i / FFT_BUFFER_SIZE; p_state->costable[i] = cos(j); p_state->sintable[i] = sin(j); } return p_state; }
void FFT::process(bool p_bInverseTransform, const double *p_lpRealIn, const double *p_lpImagIn, double *p_lpRealOut, double *p_lpImagOut) { if (!p_lpRealIn || !p_lpRealOut || !p_lpImagOut) return; // std::cerr << "FFT::process(" << m_n << "," << p_bInverseTransform << ")" << std::endl; unsigned int NumBits; unsigned int i, j, k, n; unsigned int BlockSize, BlockEnd; double angle_numerator = 2.0 * M_PI; double tr, ti; if( !MathUtilities::isPowerOfTwo(m_n) ) { std::cerr << "ERROR: FFT::process: Non-power-of-two FFT size " << m_n << " not supported in this implementation" << std::endl; return; } if( p_bInverseTransform ) angle_numerator = -angle_numerator; NumBits = numberOfBitsNeeded ( m_n ); for( i=0; i < m_n; i++ ) { j = reverseBits ( i, NumBits ); p_lpRealOut[j] = p_lpRealIn[i]; p_lpImagOut[j] = (p_lpImagIn == 0) ? 0.0 : p_lpImagIn[i]; } BlockEnd = 1; for( BlockSize = 2; BlockSize <= m_n; BlockSize <<= 1 ) { double delta_angle = angle_numerator / (double)BlockSize; double sm2 = -sin ( -2 * delta_angle ); double sm1 = -sin ( -delta_angle ); double cm2 = cos ( -2 * delta_angle ); double cm1 = cos ( -delta_angle ); double w = 2 * cm1; double ar[3], ai[3]; for( i=0; i < m_n; i += BlockSize ) { ar[2] = cm2; ar[1] = cm1; ai[2] = sm2; ai[1] = sm1; for ( j=i, n=0; n < BlockEnd; j++, n++ ) { ar[0] = w*ar[1] - ar[2]; ar[2] = ar[1]; ar[1] = ar[0]; ai[0] = w*ai[1] - ai[2]; ai[2] = ai[1]; ai[1] = ai[0]; k = j + BlockEnd; tr = ar[0]*p_lpRealOut[k] - ai[0]*p_lpImagOut[k]; ti = ar[0]*p_lpImagOut[k] + ai[0]*p_lpRealOut[k]; p_lpRealOut[k] = p_lpRealOut[j] - tr; p_lpImagOut[k] = p_lpImagOut[j] - ti; p_lpRealOut[j] += tr; p_lpImagOut[j] += ti; } } BlockEnd = BlockSize; } if( p_bInverseTransform ) { double denom = (double)m_n; for ( i=0; i < m_n; i++ ) { p_lpRealOut[i] /= denom; p_lpImagOut[i] /= denom; } } }
int main(void){ uint32_t n = 43261596; uint32_t result = reverseBits(n); return 0; }
ExifStatus ExifStripImage::readScanline(tdata_t buf, exif_uint32 row, tsample_t sample) { if (row >= mExifdir->imageLength()) { /* out of range */ // Row out of range return EXIF_ERROR; } ExifStatus status = EXIF_OK; exif_uint32 strip = computeStrip( row, sample, status ) ; if ( status != EXIF_OK ) return status; // if (strip != mCurstrip) // { /* different strip, refill */ // if (!fillStrip(strip)) // return (0); // } tsize_t bytecount; if (strip >= mNStrips) { // Strip out of range return EXIF_ERROR; } std::vector<exif_uint32> stripbytecount = mExifdir->stripByteCounts(); bytecount = stripbytecount[strip]; if (bytecount <= 0) { // Invalid strip byte count return EXIF_ERROR; } if (mScanlinesize != (tsize_t)-1 && mScanlinesize < bytecount) bytecount = mScanlinesize; std::vector<exif_uint32> stripoffset = mExifdir->stripOffsets(); exifoff_t offset = stripoffset[strip] + mExifdir->getExifOffset() ; offset += (row - strip * mExifdir->rowsPerStrip()) * bytecount ; if (mExifio->seek(offset, SEEK_SET) != offset) { // Seek error at scanline return EXIF_ERROR; } if (mExifio->read(buf, bytecount) != bytecount) { // Read error at scanline return EXIF_ERROR; } if (!mExifdir->isFillOrder( mExifio, FILLORDER_MSB2LSB ) && (mExifio->flags() & EXIF_NOBITREV) == 0) reverseBits( buf, bytecount ); return EXIF_OK ; }